简体   繁体   English

使用持续集成来修改.NET项目文件

[英]Use Continuous Integration to modify .NET project file

We have two code bases for testing and production. 我们有两个用于测试和生产的代码库。 The only differences between these two code bases are in two files: 这两个代码库之间的唯一区别是在两个文件中:

  • The config file 配置文件
  • The build file (.csproj) 生成文件(.csproj)

Maintaining two branches is a considerable effort which could be eliminated by merging the code bases into one and using a Continuous Integration (such as Hudson, eg) to modify the files according to the target environment. 维护两个分支是一项相当大的工作,可以通过将代码库合并为一个分支并使用持续集成(例如Hudson等)根据目标环境来修改文件来消除。

As of VS2010, there is a very smart solution for the config files that allows us to define different config file transformations for two build configurations "Release-Test" and "Release-Prod". 从VS2010开始,有一个非常聪明的配置文件解决方案,允许我们为两个构建配置“ Release-Test”和“ Release-Prod”定义不同的配置文件转换。

However, we have some differences that are reflected in the project file (.csproj) such as: 但是,我们在项目文件(.csproj)中存在一些差异,例如:

  • The name of the resulting assembly: Foo.exe vs. Foo-Test.exe. 生成的程序集的名称:Foo.exe与Foo-Test.exe。
  • The assembly version. 程序集版本。
  • The ClickOnce deployment settings. ClickOnce部署设置。

Is there any smart way how the csproj file can be transformed based on the build configuration, or how these settings can be extracted into a config file or C# code? 有什么聪明的方法可以根据构建配置转换csproj文件,或者如何将这些设置提取到配置文件或C#代码中?

Update: 更新:

I tried with conditional MSBuild properties in the csproj file as suggested by @JaredPar, but it has a couple of caveats (see my comments for details). 我尝试了@JaredPar所建议的csproj文件中的条件MSBuild属性,但是有一些警告(有关详细信息,请参见我的评论)。 Are there any other ways to achieve this? 还有其他方法可以做到这一点吗?

It sounds like you want to use a single csproj and control elements like the assembly name based on a specific build configuration. 听起来您想使用单个csproj和基于特定构建配置的控件元素(如程序集名称)。 If so then you're looking for the Conditional element on MSBuild properties 如果是这样,那么您正在寻找MSBuild属性上的Conditional元素

<AssemblyName Condition="'$(Configuration)' == 'Release-Prod'">Foo</AssemblyName>
<AssemblyName Condition="'$(Configuration)' == 'Release-Test'">Foo-Test</AssemblyName>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM