如何将必要的文件包含到独立客户端项目的输出中
本文关键字:独立 客户端 项目 输出 文件包 | 更新日期: 2023-09-27 18:15:46
我的解决方案包括:
Client
-启动项目,UI层。取决于:App
App
-库,应用层,汇编器。取决于:Lib1
,…
Lib1
-库,业务逻辑层。需要一个特定的文件才能正常工作:ThirdParty.dll
我将ThirdParty.dll
添加到Lib1
项目中(Add
> Existing Item...
> Add
),并将dll文件的Copy to Output Directory
属性设置为Copy Always
。现在,dll文件被复制到Lib1
输出和App
输出,但不复制到我需要的Client
输出。
什么是正确的(简单的)?很明显吗?)在每个解决方案构建上将ThirdParty.dll
复制到Client
的输出?
乌利希期刊指南ThirdParty.dll
不是引用。实际上,这是另一个参考依赖。我的问题适用于任何需要在运行应用程序的文件夹中的文件。
录制视频以确保我做对了:http://youtu.be/QwS2tOIc5yQ
添加现有项目作为链接:
我在VS2010
中有类似的问题,我最终将文件添加为Link
并将其属性更新为Copy Always
。
以您的案例为例,在CLIENT
项目中,将ThirdParty.dll
添加为Link
(add> Existing Item> add as Link),将dll文件的Copy to Output Directory
属性设置为Copy Always
。注意:它将从Project Node复制文件夹层次结构。
仅供参考:我实际上使用的是一个开源LibGit2Sharp,它需要一个dll (libGit2.dll)在输出目录中可用。因此,在UI层中,添加了包含LibGit2Sharp.dll
作为参考的应用层;我不得不将libGit2.dll
添加为Link
+ Copy Always
。这是推荐的解决方案。
文章构建:
另一种选择是为CLIENT
编写构建后脚本
要了解MSBuild
上的Copy
是如何工作的,您可以参考Microsoft.Common.targets
文件(应该是@ C:'Windows'Microsoft.NET'Framework'v4.0.30319'Microsoft.Common)。系统中的目标)
<Target
Name="CopyFilesToOutputDirectory"
DependsOnTargets="
ComputeIntermediateSatelliteAssemblies;
_CopyFilesMarkedCopyLocal;
_CopySourceItemsToOutputDirectory;
_CopyAppConfigFile;
_CopyManifestFiles;
_CheckForCompileOutputs;
_SGenCheckForOutputs">
这很简单,但奇怪的是它对你不起作用。我刚刚检查过了,这是有效的:
- 添加
ThirdParty.dll
到Lib
项目 -
Build Action
应该设置为Content
(默认值)!! - 设置
Copy to Output Directory
为Copy if newer
或Copy always
-
Lib
参考App
- 参考
Client
App
这在Visual Studio 2012中工作,但在Visual Studio 2010中似乎不起作用。
VS2010:
Target "AssignTargetPaths" skipped. Previously built successfully.
Target "_SplitProjectReferencesByFileExistence" in file "C:'windows'Microsoft.NET'Framework'v4.0.30319'Microsoft.Common.targets" from project "Test.ContentFiles'App'App.csproj" (target "GetCopyToOutputDirectoryItems" depends on it):
Task "ResolveNonMSBuildProjectOutput" skipped, due to false condition; ('$(BuildingInsideVisualStudio)'=='true' and '@(ProjectReferenceWithConfiguration)'!='') was evaluated as ('true'=='true' and ''!='').
Done building target "_SplitProjectReferencesByFileExistence" in project "App.csproj".
Target "GetCopyToOutputDirectoryXamlAppDefs" in file "C:'windows'Microsoft.NET'Framework'v4.0.30319'Microsoft.Xaml.targets" from project "Test.ContentFiles'App'App.csproj" (target "GetCopyToOutputDirectoryItems" depends on it):
Task "AssignTargetPath"
Done executing task "AssignTargetPath".
Done building target "GetCopyToOutputDirectoryXamlAppDefs" in project "App.csproj".
Target "GetCopyToOutputDirectoryItems" in file "C:'windows'Microsoft.NET'Framework'v4.0.30319'Microsoft.Common.targets" from project "C:'Users'Ark-kum'Documents'visual studio 2010'Projects'Test.ContentFiles'App'App.csproj" (entry point):
Task "MSBuild" skipped, due to false condition; ('@(_MSBuildProjectReferenceExistent)' != '' and '$(_GetChildProjectCopyToOutputDirectoryItems)' == 'true' and '%(_MSBuildProjectReferenceExistent.Private)' != 'false' and '$(UseCommonOutputDirectory)' != 'true') was evaluated as ('' != '' and 'true' == 'true' and '' != 'false' and 'false' != 'true').
Task "AssignTargetPath"
Done executing task "AssignTargetPath".
Done building target "GetCopyToOutputDirectoryItems" in project "App.csproj".
Done executing task "MSBuild".
Task "AssignTargetPath"
Done executing task "AssignTargetPath".
Done building target "GetCopyToOutputDirectoryItems" in project "Client.csproj".
Target "_CopyOutOfDateSourceItemsToOutputDirectory" in file "C:'windows'Microsoft.NET'Framework'v4.0.30319'Microsoft.Common.targets" from project "Test.ContentFiles'Client'Client.csproj" (target "_CopySourceItemsToOutputDirectory" depends on it):
Building target "_CopyOutOfDateSourceItemsToOutputDirectory" completely.
Output file "bin'Debug'FileList.App.txt" does not exist.
Task "Copy"
Copying file from "Test.ContentFiles'App'FileList.App.txt" to "bin'Debug'FileList.App.txt".
VS2012:
Target "GetCopyToOutputDirectoryItems" skipped. Previously built successfully.
Done executing task "MSBuild".
Task "AssignTargetPath"
Done executing task "AssignTargetPath".
Done building target "GetCopyToOutputDirectoryItems" in project "Client.csproj".
Target "_CopyOutOfDateSourceItemsToOutputDirectory" in file "C:'windows'Microsoft.NET'Framework'v4.0.30319'Microsoft.Common.targets" from project "Test.ContentFiles'Client'Client.csproj" (target "_CopySourceItemsToOutputDirectory" depends on it):
Building target "_CopyOutOfDateSourceItemsToOutputDirectory" completely.
Output file "bin'Debug'FileList.Lib.txt" does not exist.
Output file "bin'Debug'FileList.App.txt" does not exist.
Task "Copy"
Copying file from "Test.ContentFiles'Lib'FileList.Lib.txt" to "bin'Debug'FileList.Lib.txt".
Copying file from "Test.ContentFiles'App'FileList.App.txt" to "bin'Debug'FileList.App.txt".
从.target文件中引用:
============================================================
GetCopyToOutputDirectoryItems
Get all project items that may need to be transferred to the output directory.
This includes baggage items from transitively referenced projects. It would appear
that this target computes full transitive closure of content items for all referenced
projects; however that is not the case. It only collects the content items from its
immediate children and not children of children. The reason this happens is that
the ProjectReferenceWithConfiguration list that is consumed by _SplitProjectReferencesByFileExistence
is only populated in the current project and is empty in the children. The empty list
causes _MSBuildProjectReferenceExistent to be empty and terminates the recursion.
============================================================
您可以使用(在visual studio中)Lib1项目属性->构建事件->构建后事件命令行。
在"Post-build event命令行"编辑框中键入copy命令,将所需的文件复制到客户机输出文件夹。在该编辑框中,您可以使用各种VS宏(单击"编辑后构建"->宏)这样的:
copy path'to'ThirdParty.dll $(SolutionDir)Client'bin'Debug
也许,您将需要在第一次"Build"->"Rebuild Solution"