共享集信息为整个溶液均匀版本 [英] Shared AssemblyInfo for uniform versioning across the solution

查看:185
本文介绍了共享集信息为整个溶液均匀版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经知道了这种技术:<一href="http://blogs.msdn.com/b/jjameson/archive/2009/04/03/shared-assembly-info-in-visual-studio-projects.aspx">http://blogs.msdn.com/b/jjameson/archive/2009/04/03/shared-assembly-info-in-visual-studio-projects.aspx

I've read about this technique: http://blogs.msdn.com/b/jjameson/archive/2009/04/03/shared-assembly-info-in-visual-studio-projects.aspx

基本上,这意味着创建一个SharedAssemblyInfo.cs与版本有关大会信息,并添加此文件链接到解决方案的所有项目,因此实际的文件只存在于1的位置在磁盘上。

Basically it means to create a SharedAssemblyInfo.cs with versioning information about the assembly, and adding this file as Link to all projects of the solution, so the actual file resides only in 1 location on disk.

我的问题涉及2情景:

  1. 现有不使用这种机制的解决方案:有没有办法将ShareAssemblyInfo轻松地添加到所有项目? (可以说,我有50个项目的解决方案)。

  1. Existing solution that doesn't use this mechanism: Is there a way to easily add the ShareAssemblyInfo to all projects? (lets say i have a solution with 50 projects).

在创建创建新项目,默认情况下,一个新的AssemblyInfo.cs。但是我想自动链接到SharedAssemblyInfo为好。

When creating a new project, by default a new AssemblyInfo.cs is created. However i'd like to link automatically to the SharedAssemblyInfo as well.

对此有什么解决办法?什么是常见的做法?

Is there any solution for this? what is the common practice?

推荐答案

第一点可以用简单的文本编辑器,可以处理多个文件一次,并查找/替换来解决。只需打开所有的csproj在它和替换字符串&LT;编译包括=属性\ AssemblyInfo.cs中/&GT;

First point could be solved with simple text editor that could handle several files at once and find/replace. Just open all of your csproj in it and replace string <Compile Include="Properties\AssemblyInfo.cs" /> with

<Compile Include="..\SharedAssemblyInfo.cs">
  <Link>Properties\SharedAssemblyInfo.cs</Link>
</Compile>

我选择的编辑器是 EditPad专业版

另外,你可以只写绝对琐碎的实用工具类的:

Alternatively you could just write absolutely trivial utility like that:

var files = Directory.GetFiles(yourSolutionDir, "*.csproj", SearchOption.AllDirectories);
foreach (var f in files) {
  string contents = File.ReadAllText(f);
  string result = contents.Replace("<Compile Include=\"Properties\\AssemblyInfo.cs\" />", putSecondStringHere_ItIsJustTooLong); // :)
  File.WriteAllText(f, contents);
}

至于第二个问题...你可以看看的 Visual Studio中的自定义项目模板,但我不知道它的价值的努力。你应该IMO编写的测试,而是将检查。这将是更简单,结局其实是差不多了。

As for the second question... You could take a look at Visual Studio custom project templates , but I'm not sure it worth the efforts. You should IMO write test that will check this instead. It will be much simpler and outcome is actually almost the same.

UPD:关于编写测试来检查对一些自定义规则解决方案/项目文件。基本上,SLN /的csproj格式很简单,可以解析的没有太多的努力。所以,如果你想有 SharedAssemblyInfo.cs 链接到每个项目 - 只是解析的csproj的和检查。然后把该检查在构建服务器和每个构建运行。我们有这样的系统目前的工作,它是有成本的大约两天来写,但我们节省更多的(我们有没有更复杂的规则,多解决方案项目,所以这是值得的努力)。

UPD: About writing tests for checking solution/project files against some custom rules. Basically, sln/csproj format is simple enough to be parseable without much efforts. So if you want to have SharedAssemblyInfo.cs linked into every project - just parse csproj's and check that. Then put that checker in your build server and run it on each build. We have such system working currently and it costs something about two days to write but saved us many more (we have there more sophisticated rules and multi-solution project, so it was worth the efforts).

我不会写这个检查在这里详细,现在(它不是那么短的),但我会尽快写出来一篇博客文章 - 很可能到本周末结束。所以,如果你有兴趣 - 只是检查我的博客很快:)

I won't write about this checking in detail here right now (it is not that short), but I'm going to write blog post about it soon - most probably till the end of this week. So, if you're interested - just check my blog soon :)

UPD: <一个href="http://sparethought.word$p$pss.com/2011/07/25/checking-solutions-and-project-files-against-some-set-of-rules-at-build-time/">Here它是。

这篇关于共享集信息为整个溶液均匀版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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