VS 2022 change project variable like $(AssemblyName)

Viewed 911

How to change variables like $(AssemblyName)? I cannot find where they are defined.

enter image description here

1 Answers

Defaults for these are defined in the SDK that your project uses. For example, if your project file looks like:

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

Then you'll find these defined by the Microsoft.NET.Sdk.props file that is part of that SDK.

The definition for <AssemblyName> defaults to your project name:

<AssemblyName Condition=" '$(AssemblyName)' == '' ">$(MSBuildProjectName) 
</AssemblyName>

You can set this in your project file if you want it to be different from the default:

<PropertyGroup>
  <AssemblyName>WhateverNameIWant</AssemblyName>
</PropertyGroup>

Expert tip: If you want to see everything that is defined in your project, you can see how MSBuild processes the file by running either of these commands (they're equivalent):

  • dotnet build -pp > out.txt
  • msbuild /pp > out.txt

Spoiler: there's a lot encapsulated in the SDK.

Related