Visual Studio/msbuild: set “Content” output directory

烈酒焚心 提交于 2019-12-12 04:43:09

问题


I'm trying to achieve what markerikson was here: Visual Studio - sending "content" files to the output directory instead of a subdirectory?

The problem is, the answers there (using xcopy) is a hack. If I add a reference to the project with the content (in my case, .dlls and other data), then the content still appears under a subfolder.

How can I set Build Action -> Content and set a path for the files contained within? That propagates in such a way that if I add a reference to the containing project, the files are in the 'correct' subfolder in the referencing project's output? The content includes unmanaged code which must in the search path, i.e. in the bin folder, a subfolder will not work.

There are many content files and putting them level with my code seems crap. I have my code in a subfolder for now but it's not right..


回答1:


Edit the .csproj (Edit Project File if you have the Productivity Power Tools installed) and change the file build action to ReferenceComWrappersToCopyLocal. Rebuild.

Ultimately all IO operations boils down to the targets defined in %FrameworkDir%\v4.0.30319\Microsoft.Common.targets

Some copy targets define DestinationFolder="$(OutDir)" (copies to output without folders) and some define DestinationFiles="@(n->'$(OutDir)%(DestinationSubDirectory)%(Filename)%(Extension)')" (keeping folder structure).

You can see that items with CopyLocal=true gets copied in _CopyOutOfDateSourceItemsToOutputDirectoryAlways with DestinationFiles, while preserving the folder structure.



来源:https://stackoverflow.com/questions/13571629/visual-studio-msbuild-set-content-output-directory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!