visual-studio 在 Visual Studio 中,如何为整个文件夹设置构建操作?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2059562/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
In Visual Studio, how can I set the Build Action for an entire folder?
提问by brendan
I have a project in Visual Studio. I need to deploy some 3rd party files along with my code. Typically I would put this files in a "Resources" directory and set the Build Action on each file to "Content" and the Copy To Output Directory to "Copy if newer".
我在 Visual Studio 中有一个项目。我需要与我的代码一起部署一些 3rd 方文件。通常,我会将这些文件放在“资源”目录中,并将每个文件的构建操作设置为“内容”,将“复制到输出目录”设置为“如果更新则复制”。
Is there anyway I can set these directives at the folder level. The current project I am working with has dozens of such files and a couple of sub folders. I'd like to be able to make the entire directory as "Content" and "Copy if newer".
无论如何我可以在文件夹级别设置这些指令。我正在处理的当前项目有几十个这样的文件和几个子文件夹。我希望能够将整个目录设为“内容”和“如果更新则复制”。
回答by Arve
Create the project. Add one file as Content. Unload the project and edit the *proj file manually.
创建项目。添加一个文件作为内容。卸载项目并手动编辑 *proj 文件。
<ItemGroup>
<Content Include="myfolder**\*.dll**">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
And then in the content-ItemGroup I would replace that singe file with some MsBuild wildcard expression, *.dll, or whatever.
然后在 content-ItemGroup 中,我将用一些 MsBuild 通配符表达式、*.dll 或其他内容替换该单个文件。
回答by Freestyle076
I use Visual Studio 2012 and you can shift-click to select multiple items in the Solution Explorer then edit each item's Copy To Output Directory property all at once in the Properties window.
我使用 Visual Studio 2012,您可以按住 Shift 键并单击以在解决方案资源管理器中选择多个项目,然后在“属性”窗口中一次性编辑每个项目的“复制到输出目录”属性。
Granted this isn't equivalent to the solution you are looking for functionally, but semantically it is. And hopefully the next person to stumble across this post with a humongous folder to remedy (as is with me) won't have to dive into the .csproj file.
当然,这在功能上并不等同于您正在寻找的解决方案,但在语义上却是。希望下一个偶然发现这篇文章的人有一个巨大的文件夹来补救(就像我一样)将不必深入研究 .csproj 文件。
Hope this helps!
希望这可以帮助!
回答by Juri
回答by jcmordan
Edit your *.csproj or .vbproj file
编辑您的 *.csproj 或 .vbproj 文件
Add this tag
添加这个标签
<ItemGroup>
<Folder Include="YOUR_FOLDER_NAME_HERE/">
</ItemGroup
the final file must look like this:
最终文件必须如下所示:
<Project>
<---some more tags--->
<ItemGroup>
<Folder Include="YOUR_FOLDER_NAME_HERE\" />
</ItemGroup
<---some more tags--->
</Project>
回答by CodingYourLife
I just added this to my *.csproj file (right click Edit Project File)
我刚刚将它添加到我的 *.csproj 文件中(右键单击“编辑项目文件”)
<ItemGroup>
<Content Include="MYCUSTOMFOLDER\**">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
I know this answer is similar to @Arve but I don't know why this extra complexity with the .dll wildcard filter.
我知道这个答案类似于@Arve,但我不知道为什么 .dll 通配符过滤器会带来额外的复杂性。

