如何从子文件夹发布文件到主应用程序文件夹?



我有一个WinForms NET4.8桌面应用程序,我使用ClickOnce发布。我在项目子文件夹中有一个dll文件,我需要发布到与主应用程序相同的目录。我在我的csproj文件中有以下内容:

<PropertyGroup>
<UnreferencedDlls>libtwaindsm.dll</UnreferencedDlls>
</PropertyGroup>
<PropertyGroup>
<CopyAllFilesToSingleFolderForPackageDependsOn>
CustomCollectFiles;
$(CopyAllFilesToSingleFolderForPackageDependsOn);
</CopyAllFilesToSingleFolderForPackageDependsOn>
</PropertyGroup>
<Target Name="AfterBuild">
<Message Text="Copying unreferenced DLLs to bin" Importance="High" />
<CreateItem Include="$(UnreferencedDlls)">
<Output TaskParameter="Include" ItemName="_UnReferencedDLLs" />
</CreateItem>
<Copy SourceFiles="@(_UnReferencedDLLs)" DestinationFolder="$(OutputPath)%(RecursiveDir)" SkipUnchangedFiles="true" />
</Target>
<Target Name="CustomCollectFiles">
<Message Text="Publishing unreferenced DLLs" Importance="High" />
<ItemGroup>
<_CustomFiles Include="$(UnreferencedDlls)" />
<FilesForPackagingFromProject Include="%(_CustomFiles.Identity)">
<DestinationRelativePath>$(OutputPath)%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
</FilesForPackagingFromProject>
</ItemGroup>
</Target>

文件发布到子文件夹

我改变这一行:

<DestinationRelativePath>$(OutputPath)%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>

:

<DestinationRelativePath>$(OutputPath)%(Filename)%(Extension)</DestinationRelativePath>

但它仍然不工作。

如何强制文件发布到与应用程序相同的文件夹?

我不知道它是否能帮助你:%(RecursiveDir)

如果Include属性包含通配符**,则此元数据指定路径中替换通配符的部分。

也许你可以试着改变dll的路径。我把它放入ProjectDirlibDebug,这里是我的代码:

<PropertyGroup>
<UnreferencedDlls>lib**ClassLibrary1.dll</UnreferencedDlls>
</PropertyGroup>
<PropertyGroup>
<CopyAllFilesToSingleFolderForPackageDependsOn>
CustomCollectFiles;
$(CopyAllFilesToSingleFolderForPackageDependsOn);
</CopyAllFilesToSingleFolderForPackageDependsOn>
</PropertyGroup>
<Target Name="AfterBuild">
<Message Text="Copying unreferenced DLLs to bin" Importance="High" />
<CreateItem Include="$(UnreferencedDlls)">
<Output TaskParameter="Include" ItemName="_UnReferencedDLLs" />
</CreateItem>
<Copy SourceFiles="@(_UnReferencedDLLs)" DestinationFolder="bin%(RecursiveDir)" SkipUnchangedFiles="true" />
</Target>
<Target Name="CustomCollectFiles">
<Message Text="Publishing unreferenced DLLs" Importance="High" />
<ItemGroup>
<_CustomFiles Include="$(UnreferencedDlls)" />
<FilesForPackagingFromProject Include="%(_CustomFiles.Identity)">
<DestinationRelativePath>bin%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
</FilesForPackagingFromProject>
</ItemGroup>
</Target>

你也可以参考这个页面,希望它能帮助你。

最新更新