c# - Visual Studio 中调试和发布版本的不同构建操作

标签 c# visual-studio-2010

我有这个实现插件架构的 C# Visual Studio 解决方案。在构建调试版本时,我希望将几个插件编译到主应用程序中。在构建发布版本时,我希望保留这些 .cs 文件。

有没有一种方法可以为调试和发布构建的插件文件指定不同的构建操作?我希望它在调试版本中设置为“编译”,在发布版本中设置为“无”。

最佳答案

为此,您需要手动更改 .csproj,并在 Compile XML 元素中添加一个 Condition XML 属性,该属性对应于您只需要的文件在调试版本中。像这样:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
      ...
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
      ...
  </PropertyGroup>
  <ItemGroup>
    <!-- Add the Condition attribute here, on each of your debug only files
    Pick up one of the configuration definition configuration above -->
    <Compile Include="DebugOnlyClass1.cs" Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "/>
    <!-- normal compilation -->
    <Compile Include="Class1.cs" />
    <Compile Include="Properties\AssemblyInfo.cs" />
  </ItemGroup>
     ...
</Project>

关于c# - Visual Studio 中调试和发布版本的不同构建操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7671809/

相关文章:

c# - 从授权要求处理程序中的请求正文中读取会破坏路由

c# - 有没有办法表示很长的数字?

vb.net - 如何更改表单中所有标签的前景色?

visual-studio-2010 - 从解决方案中删除 nuget 包恢复

c# - 将外部配置复制到 Visual Studio 中的本地项目?

c# - TotalFreeSpace 和 AvailableFreeSpace 有什么区别

javascript - 如何使用 AXIOS Get 发送日期?

c# - 如何删除Windows窗体应用程序中的标题栏

visual-studio-2010 - CUDA 5 和 Visual Studio 2010 智能感知错误

c# - 静态属性/函数的性能