Since dotnet core moved back to the .csproj
format there is a new autogenerated MyProject.AssemblyInfo.cs
which contain among other.
[assembly: AssemblyCompany("MyProject")]
[assembly: AssemblyVersion("1.0.0.0")]
Note that this is automatically regenerated every build. Previously the file was found in the /obj/ directory, now it appears to be only in memory as the file can't be found on disk and clicking the error message does not open any file.
Since they are defined there I can't define them myself in the classical AssemblyInfo.cs
.
Where/how can I define the Company and Version of a project?
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.
If you want to see what's going on under the hood, checkout Microsoft.NET.GenerateAssemblyInfo.targets inside of Microsoft.NET.Sdk.
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
<project name> > Add > New Folder
.Add > New Item...
.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.
I want to extend this topic/answers with the following. As someone mentioned, this auto-generated AssemblyInfo can be an obstacle for the external tools. In my case, using FinalBuilder, I had an issue that AssemblyInfo wasn't getting updated by build action. Apparently, FinalBuilder relies on
~proj
file to find location of the AssemblyInfo. I thought, it was looking anywhere under project folder. No. So, changing thisdid only have the job, it allowed custom assembly info if built by VS IDE/MS Build. But I needed FinalBuilder do it too without manual manipulations to assembly info file. I needed to satisfy all programs, MSBuild/VS and FinalBuilder.
I solved this by adding an entry to the existing
ItemGroup
Now, having this item, FinalBuilder finds location of AssemblyInfo and modifies the file. While action
None
allows MSBuild/DevEnv ignore this entry and no longer report an error based onCompile
action that usually comes with Assembly Info entry inproj
files.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.Once saved those values can be found in
MyProject.csproj
In the file explorer properties information tab,
FileVersion
is shown as "File Version" andVersion
is shown as "Product version"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