Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 19, 2025

When invoking MSBuild with -getTargetResult to extract structured output, the SetCloudBuildVersionVars target emits cloud build commands (e.g., ##vso[task.setvariable]) that break JSON parsing in CI environments.

Changes

  • Added NBGV_SetCloudBuildVersionVars MSBuild property (defaults to true)

    • When set to false, suppresses execution of the SetCloudBuildVersionVars target
    • Updated target condition in Nerdbank.GitVersioning.targets
  • Documentation: Added property to MSBuild properties reference in msbuild.md

  • Test: Added SetCloudBuildVersionVars_CanBeDisabled to verify suppression behavior

Usage

# Suppress cloud build variable output
dotnet msbuild myProject.csproj -getTargetResult:ResolveAssemblyReferences -p:NBGV_SetCloudBuildVersionVars=false | ConvertFrom-Json

Or in project file:

<PropertyGroup>
  <NBGV_SetCloudBuildVersionVars>false</NBGV_SetCloudBuildVersionVars>
</PropertyGroup>

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • 3dovsblobprodeus2188.blob.core.windows.net
    • Triggering command: /opt/hostedtoolcache/dotnet/dotnet dotnet restore --no-dependencies /home/REDACTED/work/Nerdbank.GitVersioning/.codeql-scratch/dbs/csharp/working/32A0A2D38A721DD2A3E59F6279CF8961/missingpackages_workingdir --packages /home/REDACTED/work/Nerdbank.GitVersioning/.codeql-scratch/dbs/csharp/working/missingpackages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal --configfile /home/REDACTED/work/Nerdbank.GitVersioning/.codeql-scratch/dbs/csharp/working/nugetconfig/nuget.config --force (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Add option for disabling SetCloudBuildVersionVars target</issue_title>
<issue_description>I can work around the issue, it's not blocking me, and this is a corner case for the library, but it would be nice to have a clean fix, so if you are okay having this in the product, I can contribute a fix.

I'm invoking MsBuild targets to get build information using following code:

$references = dotnet msbuild myProject.csproj -getTargetResult:ResolveAssemblyReferences | ConvertFrom-Json

It works great locally, but if I run it in ADO pipeline, then Nerdbank.GitVersioning adds following output before the json that MSBuild prints out, that breaks parsing

##vso[task.setvariable variable=GitAssemblyInformationalVersion;]...
##vso[task.setvariable variable=GitAssemblyInformationalVersion;isOutput=true;]...
##vso[task.setvariable variable=GitBuildVersion;]...
##vso[task.setvariable variable=GitBuildVersion;isOutput=true;]...
##vso[task.setvariable variable=GitBuildVersionSimple;]...
##vso[task.setvariable variable=GitBuildVersionSimple;isOutput=true;]...
##vso[build.updatebuildnumber]...
{
  "TargetResults": { 
...

This could be avoided by adding ability of disabling SetCloudBuildVersionVars target via custom property for example.</issue_description>

<agent_instructions>Fix this by adding a condition to the SetCloudBuildVersionVars target that checks for some new property that can be used to disable it.
Be sure to document the new property on the msbuild.md page.</agent_instructions>

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


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Add option for disabling SetCloudBuildVersionVars target Add NBGV_SetCloudBuildVersionVars property to disable cloud build variable output Dec 19, 2025
Copilot AI requested a review from AArnott December 19, 2025 23:49
@AArnott AArnott marked this pull request as ready for review December 19, 2025 23:59
@AArnott AArnott enabled auto-merge December 20, 2025 00:00
@AArnott AArnott added this pull request to the merge queue Dec 20, 2025
Merged via the queue into main with commit d3ea637 Dec 20, 2025
12 checks passed
@AArnott AArnott deleted the copilot/add-disable-setcloudbuildversionvars-option branch December 20, 2025 00:51
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.

Add option for disabling SetCloudBuildVersionVars target

2 participants