Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SharedAssemblyInfo equivalent in .net core projects?

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?

like image 454
Doc Avatar asked Mar 14 '17 15:03

Doc


People also ask

What is assembly versioning in C#?

The assembly's version number, which, together with the assembly name and culture information, is part of the assembly's identity. This number is used by the runtime to enforce version policy and plays a key part in the type resolution process at run time.

What is .NET core3?

NET Core 3.0 supports Windows desktop applications using Windows Presentation Foundation (WPF) and Windows Forms. These frameworks also support using modern controls and Fluent styling from the Windows UI XAML Library (WinUI) via XAML islands. The Windows Desktop component is part of the Windows . NET Core 3.0 SDK.

What is AssemblyInfo Cs in C#?

AssemblyInfo. cs contains information about your assembly, like name, description, version, etc. You can find more details about its content reading the comments that are included in it.


2 Answers

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

like image 173
Uros Avatar answered Oct 23 '22 07:10

Uros


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.

like image 45
Eric Erhardt Avatar answered Oct 23 '22 08:10

Eric Erhardt