visual studio - Equivalent to AssemblyInfo in dotnet core/csproj

ID : 10371

viewed : 30

Tags :

Top 5 Answer for visual studio - Equivalent to AssemblyInfo in dotnet core/csproj

vote vote


As you've already noticed, you can control most of these settings in .csproj.

If you'd rather keep these in AssemblyInfo.cs, you can turn off auto-generated assembly attributes.

<PropertyGroup>    <GenerateAssemblyInfo>false</GenerateAssemblyInfo> </PropertyGroup>  

If you want to see what's going on under the hood, checkout Microsoft.NET.GenerateAssemblyInfo.targets inside of Microsoft.NET.Sdk.

vote vote


Those settings has moved into the .csproj file.

By default they don't show up but you can discover them from Visual Studio 2017 in the project properties Package tab.

Project properties, tab Package

Once saved those values can be found in MyProject.csproj

<Project Sdk="Microsoft.NET.Sdk">   <PropertyGroup>     <TargetFramework>net461</TargetFramework>     <Version></Version>     <Authors>Author 1</Authors>     <Company>Company XYZ</Company>     <Product>Product 2</Product>     <PackageId>MyApp</PackageId>     <AssemblyVersion></AssemblyVersion>     <FileVersion></FileVersion>     <NeutralLanguage>en</NeutralLanguage>     <Description>Description here</Description>     <Copyright>Copyright</Copyright>     <PackageLicenseUrl>License URL</PackageLicenseUrl>     <PackageProjectUrl>Project URL</PackageProjectUrl>     <PackageIconUrl>Icon URL</PackageIconUrl>     <RepositoryUrl>Repo URL</RepositoryUrl>     <RepositoryType>Repo type</RepositoryType>     <PackageTags>Tags</PackageTags>     <PackageReleaseNotes>Release</PackageReleaseNotes>   </PropertyGroup> 

In the file explorer properties information tab, FileVersion is shown as "File Version" and Version is shown as "Product version"

vote vote


I do the following for my .NET Standard 2.0 projects.

Create a Directory.Build.props file (e.g. in the root of your repo) and move the properties to be shared from the .csproj file to this file.

MSBuild will pick it up automatically and apply them to the autogenerated AssemblyInfo.cs.

They also get applied to the nuget package when building one with dotnet pack or via the UI in Visual Studio 2017.



<Project>     <PropertyGroup>         <Company>Some company</Company>         <Copyright>Copyright © 2020</Copyright>         <AssemblyVersion></AssemblyVersion>         <FileVersion></FileVersion>         <Version></Version>         <!-- ... -->     </PropertyGroup> </Project> 
vote vote


You can always add your own AssemblyInfo.cs, which comes in handy for InternalsVisibleToAttribute, CLSCompliantAttribute and others that are not automatically generated.

Adding AssemblyInfo.cs to a Project

  1. In Solution Explorer, right click on <project name> > Add > New Folder.

Add New Folder

  1. Name the folder "Properties".

Name folder Properties

  1. Right click on the "Properties" folder, and click Add > New Item....

Add New Item

  1. Select "Class" and name it "AssemblyInfo.cs".

Name file AssemblyInfo.cs

Suppressing Auto-Generated Attributes

If you want to move your attributes back to AssemblyInfo.cs instead of having them auto-generated, you can suppress them in MSBuild as natemcmaster pointed out in his answer.

vote vote


Adding to NightOwl888's answer, you can go one step further and add an AssemblyInfo class rather than just a plain class:

enter image description here

Top 3 video Explaining visual studio - Equivalent to AssemblyInfo in dotnet core/csproj