visual-studio 如何从 Visual Studio 编译中排除文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/219381/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 09:48:05  来源:igfitidea点击:

How to exclude files from Visual Studio compile?

visual-studiocompiler-construction

提问by Larsenal

I'm in the process of refactoring a project. I've got an entire subfolder which is known to be broken. Is there any declarative way to exclude that folder from the compile temporarily while I test the refactoring thus far?

我正在重构一个项目。我有一个已知已损坏的整个子文件夹。到目前为止,在我测试重构时,是否有任何声明性方法可以暂时从编译中排除该文件夹?

I realize I could delete the folder, but I'd like to do this through configuration if possible.

我意识到我可以删除该文件夹,但如果可能的话,我想通过配置来做到这一点。

回答by Rob Windsor

You could set the Build Action (in the Properties Window) to Nonefor the files you want excluded. You could also right-click on the folder and choose Exclude from Project.

您可以将要排除的文件的构建操作(在属性窗口中)设置为。您也可以右键单击该文件夹并选择Exclude from Project

回答by leppie

Right click all the files, and select Properties. Now set Action to None. Revert to Compile when you fixed the code :)

右键单击所有文件,然后选择属性。现在将操作设置为无。修复代码后恢复为 Compile :)

回答by Pierre

In VS 2010, right-click on the CPP module, choose Properties.

在 VS 2010 中,右键单击 CPP 模块,选择属性。

Then click on Configuration Properties -> General, Exclude from Build = Yes.

然后单击配置属性 -> 常规,从构建中排除 = 是。

"Exclude from Project" is no good, it disappears from the other Configurations as well.

“从项目中排除”不好,它也会从其他配置中消失。

回答by Mat Nadrofsky

  1. Select the files that you don't want to have compiled on the Solution Explorer.

  2. Right click and choose Options...

  3. Set the "Build Action" on the files to "None".

  1. 选择您不想在解决方案资源管理器上编译的文件。

  2. 右键单击并选择选项...

  3. 将文件上的“构建操作”设置为“无”。

That should do the trick for you!

那应该对你有用!

回答by notytony

On Visual studio 2010 or later, you can achieve the functionality in two ways.

在 Visual Studio 2010 或更高版本上,您可以通过两种方式实现该功能。

  1. Right click the file, select 'Exclude From Project'

  2. Right click the file, select 'Properties' --> select 'Configuration Properties' --> select 'General' --> choose 'Yes' from drop down menu for option 'Excluded From Build'

  1. 右键单击该文件,选择“从项目中排除

  2. 右键单击该文件,选择“属性”--> 选择“配置属性”--> 选择“常规”-->从下拉菜单中为选项“从构建中排除”选择“

回答by L.Barral

Use ExcludeFoldersFromDeployment inside <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">tag, example:

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">标签内使用 ExcludeFoldersFromDeployment ,例如:

<ExcludeFoldersFromDeployment>FolderToExclude</ExcludeFoldersFromDeployment>

For files, use:

对于文件,请使用:

<ExcludeFilesFromDeployment>File1.aspx;File2.aspx</ExcludeFilesFromDeployment>

回答by Peter Willis

In a website project type, you can set the files/folders attributes to "hidden" in Explorer to achieve the same effect.

在网站项目类型中,您可以在资源管理器中将文件/文件夹属性设置为“隐藏”以达到相同的效果。

回答by Kibbee

You should just be able to right click on the folder name in your solution explorer, and click "exclude from project".

您应该能够在解决方案资源管理器中右键单击文件夹名称,然后单击“从项目中排除”。

回答by Alan

If you have a lot of image files in a folder, so many that compilation is a painfully long task; you can rename the folder in IIS, giving the folder a .exclude extension.

如果一个文件夹中有很多图像文件,那么编译是一项非常漫长的任务;您可以在 IIS 中重命名文件夹,为文件夹提供 .exclude 扩展名。

e.g. C:\intetpub\wwwroot\yoursite\images change to C:\intetpub\wwwroot\yoursite\images.exclude

例如 C:\intetpub\wwwroot\yoursite\images 更改为 C:\intetpub\wwwroot\yoursite\images.exclude

Then when you compile your app, the .exclude folder is excluded from compilation.

然后当你编译你的应用程序时, .exclude 文件夹被排除在编译之外。

回答by OrangeKing89

This is a method I have found for IIS Website Projects.

这是我为 IIS 网站项目找到的一种方法。

Set the "Hidden" attribute for the file/folder which you want to exclude from project, and then refresh the project in Solution Explorer. For example:

为要从项目中排除的文件/文件夹设置“隐藏”属性,然后在解决方案资源管理器中刷新项目。例如:

1. Open Windows Explorer.
2. Go to the physical folder of your website.
3. Right click the file/folder which you want to exclude, and then select "Properties".
4. Check the "Hidden" attribute.
5. Click the "Refresh" button in the Visual Studio Solution Explorer

Benson Yu

于本森

Microsoft Online Community Support

微软在线社区支持

Quoted from: https://forums.asp.net/post/1997766.aspx

引自:https: //forums.asp.net/post/1997766.aspx