Skip to content

Conversation

Copy link

Copilot AI commented Nov 1, 2025

msbuild /t:pack /p:NoBuild=true ignores the NoBuild flag when reference assemblies are used, causing unwanted rebuilds that overwrite signed DLLs.

Root Cause

The _SdkGetReferenceAssemblies target unconditionally depends on Build, forcing reference assembly projects to rebuild during pack operations regardless of the NoBuild property.

Changes

Modified Source/MSBuild.Sdk.Extras/Build/ReferenceAssembly.targets:

  • Introduced _SdkGetReferenceAssembliesWithBuild as a conditional build gate:

    <Target Name="_SdkGetReferenceAssembliesWithBuild" 
            DependsOnTargets="Build" 
            Condition="'$(NoBuild)' != 'true'" />
  • Updated _SdkGetReferenceAssemblies to depend on the conditional target instead of Build directly

  • Modified _ExtrasGetRefsForPackage to propagate NoBuild=$(NoBuild) to reference assembly project invocations

When NoBuild is true, the target executes but skips the Build dependency, using existing outputs from disk.

Original prompt

This section details on the original issue you should resolve

<issue_title>Pack always builds a project with reference assemblies</issue_title>
<issue_description>1. Add a reference assembly to a project, like described in the blog (e.g. https://github.com/AzureAD/microsoft-authentication-library-for-dotnet)

  1. Build the sln, which builds both project and ref project
  2. Pack via "msbuild /t:pack /p:nobuild=true"

Actual:
The pack does not obey the "nobuild" setting. It needs to rebuild because the ref assemblies are not actually produced in step 2

Expected:
Pack should not rebuild

Impact:
Because pack rebuilds, some DLLs are overwritten. This makes DLL signing difficult. Ideally all DLLs should be on disk and /t:pack just packs

Workaround:
I can workaround by packing twice. So my release pipeline looks like this:

  • build
  • pack
  • sign lib assemblies
  • sign ref assemblies
  • pack /nobuild

</issue_description>

Comments on the Issue (you are @copilot in this section)

@clairernovotny I'll look into this when I can, but in general, I would not suggest making sign as part of the build step. I'd have build/pack do just that, then send the nuget to the signing mechanism once built (you can always extract/repack the nuget with zip before the nuget itself is signed).

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Fix pack command to respect nobuild setting Fix Pack to respect NoBuild property for reference assemblies Nov 1, 2025
Copilot AI requested a review from clairernovotny November 1, 2025 21:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pack always builds a project with reference assemblies

2 participants