Exclude whole files based on configuration from build in VS2008

空扰寡人 提交于 2019-12-22 04:35:28

问题


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.

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?


回答1:


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>

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

and at the bottom have

#endif

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.



来源:https://stackoverflow.com/questions/2370353/exclude-whole-files-based-on-configuration-from-build-in-vs2008

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!