简体   繁体   English

如何强制Console App Project在构建中包含一个文件夹?

[英]How do you force a Console App Project to include a folder in the build?

Let's say you create a C# console application, in Visual Studio, and within the application you create a folder called "Content". 假设您在Visual Studio中创建了一个C#控制台应用程序,并在应用程序中创建了一个名为“Content”的文件夹。 How would you force the project to include this folder during the build? 在构建期间,您如何强制项目包含此文件夹?

What I mean by this, is I want this "Content" folder to be present in /bin/Debug when I build the project. 我的意思是,我希望在构建项目时,这个“Content”文件夹出现在/ bin / Debug中。 Currently, this new "Content" folder is not being outputted/created in the /bin/Debug folder. 目前,这个新的“Content”文件夹没有在/ bin / Debug文件夹中输出/创建。

For each file within your Content folder, you should be able to set the Copy to Output Directory property to Copy Always, in the Properties panel. 对于Content文件夹中的每个文件,您应该能够在“属性”面板中将“复制到输出目录”属性设置为“始终复制”。

截图

I don't think you can apply this property to a folder directly, so if you're only looking to include blank folder, it might just be easier to get the console app to create the blank folder you require at runtime . 我认为您不能直接将此属性应用于文件夹,因此如果您只想包含空白文件夹,则可能更容易让控制台应用程序在运行时创建您需要的空白文件夹

Right click on the project, select Properties > Build Events, then put the following script in the Post-build event command line: 右键单击该项目,选择Properties> Build Events,然后将以下脚本放在Post-build事件命令行中:

xcopy /E "$(ProjectDir)\Content" "$(TargetDir)\Content\*"

Screenshot: 截图:

项目属性

This script is stored in your .csproj file, so the build will work in the TFS Build Agent as well. 此脚本存储在.csproj文件中,因此构建也将在TFS构建代理中运行。

If you have files in the folder, you would just set "Copy to Output Directory" to "Copy Always". 如果文件夹中有文件,则只需将“复制到输出目录”设置为“始终复制”。 If you don't really have any files, I usually just add a ReadMe.txt 如果你真的没有任何文件,我通常只需添加一个ReadMe.txt

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 你如何使用 webpack 包含整个 polyfills 文件夹? - How do you include an entire folder of polyfills using webpack? 如何获得要在构建机器上构建的NUnit测试项目? - How do you get an NUnit test project to build on a build machine? 如何创建一个包含项目中所有文件的文件夹? - How do you create a folder containing all the files in a project? 如何更改 .NET Core 项目中“wwwroot”文件夹的图标? - How do you change the icon of the `wwwroot` folder in a .NET Core project? 在WPF应用程序中,如何覆盖“控制台关闭”命令? - In a WPF app how do you override the Console Close command? 您如何在 azure deveops 管道中构建单个项目工件 - How do you build individual project artifacts in azure deveops pipeline 如何使用NAnt 0.90构建Windows Workflow项目? - How do you build a Windows Workflow Project with NAnt 0.90? 在项目构建中包含(但不编译)源文件 - Include (but do NOT compile) source file in project build C#如何将控制台应用程序添加到MonoGame项目 - C# How do I add a console app to a MonoGame project 如何访问 WinUI 3 应用程序项目中的资产文件夹? - How do I access Assets folder in WinUI 3 app project?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM