10
votes

When I wanted multiple projects in a solution to share the same assembly informations (mainly AssemblyVersion), I used to use the tecnique explained here: https://blogs.msdn.microsoft.com/jjameson/2009/04/03/shared-assembly-info-in-visual-studio-projects/

Now we're working on a solution of .net core and asp.net core projects and we want all projects to share the same AssemblyVersion, but now each project's version is stored inside it's .csproj file (we're using vs2017)

I tried with generating info with <GenerateAssemblyProductAttribute>true</GenerateAssemblyProductAttribute> but the new file is created at build-time

Is there a way to centralize this information like in the "old" SharedAssemblyInfo.cs way?

2
it's not. I already know where .net core assembly info are written, I'm asking how to centralize this info for multiple projectsDoc
I must admit I have not tried it, but have you read the first answer? It shows how to disable the usage of the information from csproj and thus should allow you to keep using your existing approach (using a SharedAssemblyInfo.cs file). Also see Hans' Answer which is essentially just that.Christian.K

2 Answers

17
votes

You can add a Directory.Build.props file above all the .csproj files that you want to default properties for. This .props file will automatically be imported in all the .csproj files below it. You can set common properties in it:

<Project>
  <PropertyGroup>
    <Company>Erhardt Enterprises</Company>
    <Copyright>Erhardt Enterprises ©</Copyright>
  </PropertyGroup>
</Project>

And these MSBuild properties will apply to all the .csproj files under it. So when the assembly attributes are generated, these values will be used across all projects.

Here is the mapping of all MSBuild properties to assembly attributes.

1
votes

You can create .props file (for example common.props) and put common project configuration in this file:

common.props:

<Project>
  <PropertyGroup>
    <AspNetCoreVersion>2.0.0</AspNetCoreVersion>
  </PropertyGroup>
</Project>

project1.csproj:

<Project Sdk="Microsoft.NET.Sdk.Web">

  <Import Project=".\common.props" />

  ...

</Project>

project2.csproj:

<Project Sdk="Microsoft.NET.Sdk.Web">

  <Import Project=".\common.props" />

  ...

</Project>

You can find more info on this link