Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I correct the output directory of a CI/CD NuGet package build using Visual Studio Team Services?

I've just started trying to configure a CI/CD process using Visual Studio Team Services, with a view to having a gated check-in process which then automatically packs and pushes the output to a private NuGet Feed. I'm successfully getting through the "Get Sources" task which exists natively in the build definition, however my package task is failing at this stage:

d:\a\_tool\NuGet\4.0.0\x64\nuget.exe pack 
d:\a\1\s\Core\Core\Core.csproj -NonInteractive -
OutputDirectory d:\a\1\a -Properties Configuration=$Release;OutDir=$(OutDir) 
-Symbols -version 1.0.0-CI-20170811-095629 -Verbosity Detailed
NuGet Version: 4.0.0.2283
Attempting to build package from 'Core.csproj'.
MSBuild auto-detection: using msbuild version '14.0' from 'C:\Program Files (x86)\MSBuild\14.0\bin\amd64'. Use option -MSBuildVersion to force nuget to use a specific version of MSBuild.
NuGet.CommandLine.CommandLineException: Unable to find 'd:\a\1\s\Core\Core\$(OutDir)\Core.dll'. Make sure the project has been built.

Essentially, the 2nd line of the log demonstrates that my project file is in d:\a\1\s, however the output is directed to d\a\1\a - not the same place. The instruction to NuGet to package my file then looks in the correct location (d:\a\1\s), but the file isn't here.

I understand that I can specify a Package Folder within the build definition, however I've not changed this from the default ($(Build.ArtifactStagingDirectory)) - I expect this to work natively, but for reasons I can't explain, it's not.

Is there a token or wildcard I can provide in an additional build property that will rectify this? I've taken the guidance of the first posted answer in here and changed $(Build.ArtifactStagingDirectory) to $(Build.Repository.LocalPath), which gets me much closer to the goal as the error now reads -OutputDirectory d:\a\1\s\... - I've tried manually putting a variety of sensible paths no the end of this, but the error persists.

like image 741
Ashilta Avatar asked Sep 15 '25 08:09

Ashilta


2 Answers

Refer to this article. It has the build variables for the TFS/VSTS environment.

$(Build.ArtifactStagingDirectory) itself refers to the \1\a folder. You might want to try the $(Build.Repository.LocalPath) variable.

Not a 100% if it would work, but might as well try.

like image 139
BikerDude Avatar answered Sep 16 '25 22:09

BikerDude


The issue is related to OutDir=$(OutDir) instead of OutputDirectory.

The OutputDirectory specifies the folder in which the created package is stored and the OutDir specifies the build output, but the project need to be built before NuGet pack task, so you need to add Visual Studio Build task or related to build project.

You can leave Additional build properties box blank to use default output per to configuration, because you just need to know the package stored path to push package to remote feed.

If you want to change build output, you can specify /p:OutDir msbuild argument to change build output location. For example:

  1. Visual Studio Build task (MSBuild Arguments: /p:OutDir=$(Build.ArtifactStagingDirectory))
  2. NuGet pack task (Additional build properties: OutDir=$(Build.ArtifactStagingDirectory))

BTW, to change package stored location, you need to specify OutputDirectory.

like image 33
starian chen-MSFT Avatar answered Sep 16 '25 23:09

starian chen-MSFT