Shared AssemblyInfo for uniform versioning across the solution

前端 未结 4 605
时光说笑
时光说笑 2020-11-30 22:04

I\'ve read about this technique: Shared assembly info in VS projects - JJameson\'s blog

Basically it means to create a SharedAssemblyInfo.cs with versioning informat

4条回答
  •  借酒劲吻你
    2020-11-30 22:26

    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 with

    
      Properties\SharedAssemblyInfo.cs
    
    

    Alternatively you could write a 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("", putSecondStringHere_ItIsJustTooLong); // :)
      File.WriteAllText(f, contents);
    }
    

    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: 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: Here it is.

提交回复
热议问题