11

I'm developing a REST Api using ASP.NET Core. I used to shared assembly info across my solution using a shared file containing common attributes such as AssemblyCompany, AssemblyCopyright, AssemblyTrademark and AssemblyVersion. In this way all of my projects in a solution would be compiled with the same Assembly info attributes.

In ASP.NET Core these attributes are now defined in the project.json file. Is there a way to share these attributes in a similar way?

natemcmaster
  • 25,673
  • 6
  • 78
  • 100
Janni Kajbrink
  • 661
  • 2
  • 7
  • 21
  • I'm a bit behind the times and only just encountering this now, and it is SO ANNOYING. The shared AssemblyInfo.cs approach was elegant and easy. Very frustrating that it changed to such a clumsy way of doing it instead. – BittermanAndy Sep 10 '20 at 11:07

2 Answers2

9

In case others get by here and are looking for a solution that works with .Net Core > 2.1 and the new .csproj project files:

After some research I got it working using Directory.Build.props file in a parent directory. You can find the sample code and some more information in this repository.

Marc
  • 4,715
  • 3
  • 27
  • 34
0

With the exception of AssemblyVersion, the assembly attributes you mentioned can still be defined in a shared file. This file can be added to the project under "buildOptions".

Example:

{
  "buildOptions": {
    "compile": "../shared/AssemblyInfo.cs"
  }
}

See https://learn.microsoft.com/en-us/dotnet/articles/core/tools/project-json#buildoptions for more details.

AssemblyVersion can't be shared because it is always generated from the "version" value in project.json. "version" defaults to 1.0.0 if not specified.

Other attributes, such as AssemblyCopyright, will not be generated if their corresponding field is left empty in project.json.

natemcmaster
  • 25,673
  • 6
  • 78
  • 100
  • 1
    Fails after VS2017 with the new msbuild based project types that does not make use of project.json And adding a linked file as we always have been able to do, does not work as a AssemblyInfo file is generated at compile time using meta data provided in the project. – Daniel Mar 24 '17 at 13:37
  • 1
    Checkout this answer for some details on assembly info in csproj. http://stackoverflow.com/a/42183749/2526265 – natemcmaster Mar 24 '17 at 14:42