Updating .NET Project Links (in the configuration file)

I have a solution consisting of several projects, including:

Foo.Bar.Client
Foo.Common

Foo.Bar.Client dependent on the components in Foo.Common . And Foo.Common does not have its own configuration file; its settings are stored in the client application configuration file using it, in this case Foo.Bar.Client .
Thus, the configuration file for Foo.Bar.Client contains

  <configSections> <section name="BletchConfiguration" type="Foo.Common.Bletch, Version=1.1.0.0, ..."/> .... </configSections> 

I was instructed to set up our numbering version so that part of the β€œrevision” corresponds to the latest set of changes (in our case, the HEAD version number, since we use Subversion), for example. from "1.1.0.0" to "1.1.0.12345".

So, I implemented the "general" build-version-info module, as described here . And I modified our assembly NAnt script to capture the version number and update the general assembly-information file.

However, I did not expect version numbers to be embedded in the configuration file (s). Is there a (relatively) painless way to automate updating version numbers in configuration files?

Obviously, I can split the β€œgeneral” assembly into a separate solution.
I could also configure common components using IoC, which would eliminate the need for a configuration section for a specific assembly.
However, any of these approaches involves some risk and time ... both of which I believe that the authorities, who will, whenever possible, avoid, if possible (at least for now).

+4
source share
2 answers

The quick answer is if you do not support multiple simultaneous versions of Foo.Common.dll in your application, I just omitted the version number from the configuration section.

 <configSections> <section name="BletchConfiguration" type="Foo.Common.Bletch, Foo.Common"/> .... </configSections> 

This does not apply to the section area of ​​the file configuration section - it is an integral .net thing and convention used everywhere.

[EDIT]

I can not find any documentation regarding which parts are optional. The MSDN documentation simply states the structure http://msdn.microsoft.com/en-us/library/ms228245.aspx However, there are a few experiments from memory ... (this is quite flexible - square brackets mean optional)

If your DLL is in the GAC, you will need the version ... FullTypeAndNamespace, AssemblyNameWithoutExtension, Version, Culture, PublicKeyToken [,PlatformType]

If your DLL is in the bin directory FullTypeAndNamespace, AssemblyNameWithoutExtension [,Version, Culture, PublicKeyToken] [,PlatformType]

Therefore, the first two parts are required, because the application must know which assembly to look for, for the type you specify.

You may have optional components in any order (because they are structured as key = value pairs, order does not matter). Just specify the elements you want to limit, omit the rest.

So, in the example that I gave, the CLR will load the first DLL that matches the name and contains the required type.

+2
source

I would not often change my AssemblyVersion. You must update the AssemblyFileVersion for each assembly (so you can talk about this separately), but changing AssemblyVersion in each assembly is quite problematic.

What are the differences between AssemblyVersion, AssemblyFileVersion and AssemblyInformationalVersion?

EDIT: When I need to update AssemblyVersion, I run a Powershell script that finds the files that need to be changed, validates them and makes the changes. I manually submit the changes after checking a subset of the files.

Here is the script to update the actual AssemblyVersion:

 get-childitem . -rec -include AssemblyInfo.cs | select-string "assembly: AssemblyVersion(" -simplematch -list | % { & p4 sync $_.path; & p4 edit $_.path; (get-content $_.Path) |% { $_ -replace "assembly: AssemblyVersion\(`"\d\.\d\.\d\.\d", "assembly: AssemblyVersion(`"2.0.0.0" } | set-content $_.Path -Encoding UTF8 } 

Here you can update the link to projects from 1.5.0.0 to 2.0.0.0:

 get-childitem . -rec -include *.csproj | select-string "<Reference Include=`"Acme.SomeProduct," -simplematch -list | % { & p4 sync $_.path; & p4 edit $_.path; (get-content $_.Path) |% { $_ -replace "<Reference Include=`"Acme\.SomeProduct, Version=1\.5\.0\.0,", "<Reference Include=`"Acme.SomeProduct, Version=2.0.0.0," } | set-content $_.Path -Encoding UTF8 } 
+1
source

Source: https://habr.com/ru/post/1382353/


All Articles