visual studio - Equivalent to AssemblyInfo in dotnet core/csproj

ID : 10371

viewed : 30

Tags : visual-studiovisual-studio-2017.net-coreassemblyinfovisual-studio

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

vote vote

90

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

86

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>1.2.3.4</Version>     <Authors>Author 1</Authors>     <Company>Company XYZ</Company>     <Product>Product 2</Product>     <PackageId>MyApp</PackageId>     <AssemblyVersion>2.0.0.0</AssemblyVersion>     <FileVersion>3.0.0.0</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

73

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.

See https://docs.microsoft.com/en-us/visualstudio/msbuild/customize-your-build

Example:

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

65

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

53

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

Related QUESTION?