AssemblyInfo general information for consistent version control in a solution

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

Basically, this means creating SharedAssemblyInfo.cs with version information for the assembly and adding this file as a link to all solution projects, so the actual file is only in 1 place on disk.

My question is about two scenarios:

  • An existing solution that does not use this mechanism: is there a way to easily add ShareAssemblyInfo to all projects? (let's say I have a solution with 50 projects).

  • When you create a new project, a new AssemblyInfo.cs is created by default. However, I would like to automatically link to SharedAssemblyInfo.

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

+60
c # .net-assembly visual-studio visual-studio-2010
Jul 21 2018-11-11T00:
source share
3 answers

The first point can be solved with a simple text editor that can process several files at once and find / replace. Just open all your csprojs and replace the line <Compile Include="Properties\AssemblyInfo.cs" /> with

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

Alternatively, you can write such a utility:

 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); } 

Regarding the second question ... You can take a look at Visual Studio Custom Project Templates , but I'm not sure if it is worth the effort. You should write a test message that will check this instead. It will be much easier, and the result will not change much.

UPD: About writing tests to validate decision / project files against some custom rules. In principle, the sln / csproj format is simple enough so that it can be analyzed without much effort. Therefore, if you want to link SharedAssemblyInfo.cs in each project - just analyze csproj and check it out. Then put this check on your assembly server and run it on each assembly. We have such a system that is currently working, and it costs about two days to write, but it saved us a lot (we have more complex rules and a multi-implementation project, so it was worth the effort).

I will not write about this check in detail here right now (this is not so short), but I am going to write a blog post about this in the near future - most likely, by the end of this week. So, if you're interested, just check out my blog soon :)

UPD: Here it is.

+45
Jul 21 '11 at 6:01
source share

In VS 2010, you can link to a common assembly information file. Ashish Jain has a good blog post about this: Sharing build versions in projects in a solution .

After creating a general assembly information file at the solution level, its instructions for linking to it from the project:

  • Right-click on the project where you want to add the Shared assembly file and select Add → Existing Element ...

  • Select the file "SharedAssemblyInfo.cs" from the solution folder.

  • Instead of "Add", click on the arrow next to "Add" and click "Add as" Link "

  • Drag the added linked file along with AssemblyInfo.cs into the same folder.

  • Repeat steps 1 through 4 for all projects for which you want to add a shared build file.

I tried this and it works.

+44
May 23 '13 at 23:56
source share

I created an application to automatically increase the file version.

  • Download Applicaiton
  • add the following line to pre-build the event command line

C: \ temp \ IncrementFileVersion.exe $ (SolutionDir) \ Properties \ AssemblyInfo.cs Build a project To make this simple, the application displays only messages, if there is an error, to make sure that it worked fine, you will need to check the file version in " Build Info "

Note. To fill in the fields, you will have to reload the solution in Visual studio for the "Assembly Information" button, however your output file will have an updated version.

For suggestions and requests, please write to me at telson_alva@yahoo.com

0
Jun 23 '17 at 11:17
source share



All Articles