排除根据配置整个文件从建立在VS2008根据、文件

2023-09-04 09:26:43 作者:残花一夏

我有我的项目三种不同的配置,这三个并不需要所有的文件可用于构筑的应用程序。其实我想preFER如果我可以从构建,这将使我的应用程序多了几分轻巧排除这些文件。

I have three different configurations on my project, all three do not require all files to be build into the application. Actually I'd prefer if I could exclude those files from the build, which would make my application a little more lightweight.

我正在寻找的是#如果MYCONFIG #如果DEBUG 语句,但对于文件。我已经读到这可以通过手动编辑的csproj文件来实现,但是我找不到了...以及是否有其他办法吗?

What I'm looking for is #if MYCONFIG or #if DEBUG statement but for files. I've already read that this can be accomplished by manually editing the csproj file, but I can't find that anymore...and are there other ways?

推荐答案

有两种不同的方式: 在您的csproj文件,你将有如下几个部分:

There are two different ways: In your csproj files, you will have sections that look like this:

<ItemGroup>
    <Compile Include="Helper.cs" />
    <Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>

你可以做的是建立一个新的项目配置(构建的菜单,配置管理器的,选择的新的距离的活动解决方案配置的下拉列表),则ItemGroup节点手动改成这样:

What you can do is set up a new project configuration (Build menu, Configuration Manager, select New from the Active solution configuration dropdown), then manually change the ItemGroup node to this:

<ItemGroup Condition=" '$(Configuration)' == 'MyNewConfiguration' ">
    <Compile Include="Helper.cs" />
    <Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>

第二种方式,因为你提到你的问题,是使用的条件调试符号。在你的文件的顶部,有语句

The second way, as you referred to in your question, is to use conditional debug symbols. At the top of your file, have the statement

#if MYDEBUGSYMBOL

和在底部有

#endif

,那么你可以定义调试符号;右clickon您的项目文件,选择的属性的,进入的构建的标签,在条件编译符号进入调试符号的文本框。

then you can define the debug symbols; right clickon your project file, select Properties, go to the Build tab, and enter the debug symbol in the Conditional compilation symbols textbox.

我可能会坚持使用第一种方法。

I would probably stick with the first method.