msbuild icon indicating copy to clipboard operation
msbuild copied to clipboard

Passing AssemblyName as argument of MSBuild propagates it to referenced projects.

Open ighristov opened this issue 1 year ago • 2 comments

Version Used: .NET SDK 9.0.203

Steps to Reproduce:

  1. Create a .NET Class Library. Name it P1.
  2. Create a second .NET Class Library. Name it P2.
  3. Add project reference in P2 to P1.
  4. Build P2 from command-line using msbuild.exe with the following command:
msbuild.exe P2.csproj /p:AssemblyName="P3"

A minimal repro, with source-code provided, is ideal. Most compiler/language issues can be distilled into a snippet that can be pasted into sharplab.

Diagnostic Id: n/a

Expected Behavior:

  • Have P3.dll in P2's /bin folder.
  • Have P1.dll in P1's /bin folder, because the argument 'AssemblyName' is not supposed to be propagated.

Actual Behavior:

  • Have P3.dll in P2's /bin folder.
  • Have P3.dll in P1's /bin folder.
  • Both dlls contain their respective codebase.

When inspecting the P3.dll in P2 project folder, a circular reference is observed:

Image

The issue is reproducible with .NET and .NET Framework SDK-style project files. I've attached 2 .zips, demonstrating the issue in .NET 8 and .NET Framework 4.6.2. ProjRef_net462.zip ProjRef_net8.zip

ighristov avatar May 07 '25 18:05 ighristov

You can set the AssemblyName property in P2's csproj file, then it's not propagated. Command line arguments are propagated, that's by design.

jjonescz avatar May 08 '25 10:05 jjonescz

MSBuild triage: This is by design. Please take a look at this document for more information https://learn.microsoft.com/en-us/visualstudio/msbuild/msbuild-properties?view=visualstudio#global-properties.

AlesProkop avatar Jul 07 '26 13:07 AlesProkop