根据Visual Studio配置包含/排除文件 [英] Include/Exclude files per visual studio configuration

查看:301
本文介绍了根据Visual Studio配置包含/排除文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Visual Studio项目中有多个文件夹.我对该项目也有相同数量的配置. (一个代码库可运行多个站点).

I have multiple folders in a visual studio project. I also have the same amount of configurations for this project. (One code base runs multiple sites).

我只希望每个配置包含一个文件夹.

I only want one folder per configuration to be included.

现在,每种配置都包括每个单独的文件夹.然后,我必须在构建后手动删除多余的文件夹(如果我愿意的话).

Right now, every configuration includes every single folder. Then, I have to manually delete the extra folders after build (if I so choose).

这也减慢了我们持续集成的速度,因为它必须处理所有额外的文件.

This also slows down our continuous integration builds, because all the extra files it has to process.

这不能通过从项目中排除"/包含在项目中"上下文菜单项来实现.这样会将其从整个项目中完全删除.

This cannot be achieved by the "Exclude From Project" / "Include In Project" context menu item. That would remove it from the whole project completely.

我只需要为某些配置提供某些文件夹.

I need certain folders included only for certain configurations.

X代码(iOS开发)通过使用目标成员身份"来处理此问题....您可以告诉某个文件仅包含在某个目标中.

X Code (iOS devleopment) handles this by using "Target Memberships"... You can tell a certain file to only be included in a certain target.

试图在VS中做同样的事情.

Trying to do the same in VS.

请帮助!

推荐答案

您必须手动编辑.csproj文件,该文件实际上只是MSBUILD文件. (右键单击,在记事本或其他文本编辑器中打开)

You must manually edit your .csproj file, which is really just an MSBUILD file. (Right click, open in notepad or other text editor)

这是一个例子.我复制了默认的Program.cs,并为DEBUG创建了一个,为RELEASE创建了一个.

Here's an example. I duplicated the default Program.cs and created one for DEBUG and one for RELEASE.

在正常情况下,构建此类时会出现错误,因为我两次定义了相同的类.

Under normal conditions when I build this I would get an error because I have defined the same class twice.

但是在按如下方式编辑.csproj文件之后,它们现在根据我选择的配置独立构建.

But after editing the .csproj file as below, they now independently build depending on the configuration that I have selected.

  <ItemGroup>
    <Compile Include="DebugFiles\ProgramForDebug.cs" Condition=" '$(Configuration)' == 'Debug' "/>
    <Compile Include="ReleaseFiles\ProgramForRelease.cs"  Condition=" '$(Configuration)' == 'Release' "/>
    <Compile Include="Properties\AssemblyInfo.cs" />
  </ItemGroup>

我可能会补充说,可能有更好的方法来完成您的工作.也许使用config转换(也许在不同的配置中指定要用于您的环境的类的名称),但是无论哪种方式,上面的示例都可以肯定地满足您的要求.

I might add, there is probably a better way to accomplish what you're doing. Perhaps using config transforms (maybe where different configurations specify the name of the class to use for your environment), but either way the above example will definitely accomplish what you're asking.

这篇关于根据Visual Studio配置包含/排除文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆