GoCD Nuget issue - nuget

I have a project and my agent does have nuget installed - Not sue what I am doign wwong
12:01:14.195 [go] Start to build DemoApp/20/second/1/secondJob on vivians-mbp-2.delta.rl.delta.com [/Users/vivianaranha/Library/Application Support/Go Agent]
12:01:14.195 [go] Current job status: passed.
12:01:14.195 [go] Start to execute task: <exec command="nuget restore packages.config -PackagesDirectory ..\..\packages" workingdir="EMApp\EMApp\EMApp.iOS" />.
12:01:14.199 Error happened while attempting to execute 'nuget restore packages.config -PackagesDirectory ..\..\packages'.
Please make sure [nuget restore packages.config -PackagesDirectory ..\..\packages] can be executed on this agent.
12:01:14.199 [Debug Information] Environment variable PATH: /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/usr/local/bin
12:01:14.206 [go] Current job status: failed.

Have you tried setting the build details to be more verbose? Also, from when i do it I have the build use the nuget.exe saved in the source control, not on the build agent

You are making a common mistake in GoCD expecting exec task to be a shell execution.
By that build log, I can tell that your configuration in xml is
<exec command="nuget restore packages.config -PackagesDirectory ..\..\packages" workingdir="EMApp\EMApp\EMApp.iOS">
</exec>
That means GoCD would be trying to execute a file whose path is nuget restore packages.config -PackagesDirectory ..\..\packages, which does not exist.
GoCD exec task requires you to explicitly separate process executable and all arguments. So the above nuget example would have to be configured like so:
<exec command="nuget" workingdir="EMApp\EMApp\EMApp.iOS">
<arg>restore</arg>
<arg>packages.config</arg>
<arg>-PackagesDirectory</arg>
<arg>..\..\packages</arg>
</exec>
More tips on task setup:
If nuget.exe is not in the PATH, you'll need to configure full file path e.g. command="C:\nuget\nuget.exe"
Here is a nice blog post on exec tasks
If you don't like setting up process and arguments separately like this, try script executor plugin which will start a shell.
Edit 1
On mac you would need to run nuget with mono. So the process executable is mono:
<exec command="mono" workingdir="EMApp\EMApp\EMApp.iOS">
<arg>/path/to/nuget</arg>
<arg>restore</arg>
<arg>packages.config</arg>
<arg>-PackagesDirectory</arg>
<arg>..\..\packages</arg>
</exec>

Related

Azure Function PostBuild File Copy being lost

I'm doing an MSBuild in Visual Studio of a C# Azure Function. Most of the content is placed in $(TargetDir)/bin. I need to copy the Api.dll from there to $(TargetDir) for Entity Framework Migration. eg:
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="echo copy /Y "$(TargetDir)bin\Api.dll" "$(TargetDir)"" />
</Target>
The copy appears to work, but is not there when the build is completed.
If I do the copy as a batch file with a directory listing before and after the file IS copied.
But its not there when I try to do add-migration
So I guess the project build is recreating the Target folder after PostBuildEvent ???
The Api project builds OK but when I run add-migration fist I get:
An assembly specified in the application dependencies manifest (Api.deps.json) was not found:
package: 'Api', version: '1.0.0'
path: 'Api.dll'
The dll is not in $(TargetDir) but one folder lower in $(TargetDir)bin
this is due to RemoveRuntimeDependencies task removes this assemblies. Add <_FunctionsSkipCleanOutput>true<_FunctionsSkipCleanOutput> to .csprojwithinPropertyGroup.

Configure Roslyn analyser in Azure Devops Yaml

I need help. I am trying to configure roslyn code analyser in azure devops. I need the MsCommandLine to add this roslyn analyser.
and the build task generated is
- task: RoslynAnalyzers#3 inputs:
userProvideBuildInfo: 'msBuildInfo'
msBuildVersion: '16.0'
msBuildArchitecture: 'amd64'
msBuildCommandline: '$(Parameters.solution)'
But i am getting error
MSBUILD : error MSB1003: Specify a project or solution file. The
current working directory does not contain a project or solution
file.
What should be added in MSBuildCommandLine to specify source directory of the project?
I have referred to https://secdevtools.azurewebsites.net/helpRoslynAnalyzers.html
and https://www.1eswiki.com/wiki/Secure_Development_Tools_Extension_For_Azure_DevOps .
I am not getting any clue about this MSCommandLine. How to specify it?
The commandline should begin with a full path to MSBuild.exe.
The command will run with $(Build.SourcesDirectory) as the working directory. You may specify the full path to MSBuild.exe, and try again.
The commandline should begin with a full path to MSBuild.exe or dotnet.exe. So your msBuildCommandline statement should look like below
msBuildCommandline: "C:\Program Files\dotnet\dotnet.exe" build '$(Parameters.solution)' ...

nuget tfs build 2015

I am trying to use NuGet to package and publish the package with TFS Build 2015 to local NuGet Server. I am getting error , I am not sure what am i missing. Thanks for Help.
Here is Error
Starting task: NuGet Packager
Set workingFolder to default: C:\Lucky\agent\tasks\NuGetPackager\0.1.58
Executing the powershell script: C:\Lucky\agent\tasks\NuGetPackager\0.1.58\NuGetPackager.ps1
Checking pattern is specified
No Pattern found in solution parameter.
Found files: 1
--File: "C:\Lucky\agent_work\1\s\Dev\FabrikamFiber.CallCenter"
The property DirectoryName does not exist or was not found.
Creating Nuget Arguments:
--ARGS: pack "C:\Lucky\agent_work\1\s\Dev\FabrikamFiber.CallCenter" -OutputDirectory "C:\Lucky\agent_work\1\s" -Properties Configuration=Release
Invoking nuget with pack "C:\Lucky\agent_work\1\s\Dev\FabrikamFiber.CallCenter" -OutputDirectory "C:\Lucky\agent_work\1\s" -Properties Configuration=Release on
C:\Lucky\agent\agent\worker\tools\NuGet.exe pack "C:\Lucky\agent_work\1\s\Dev\FabrikamFiber.CallCenter" -OutputDirectory "C:\Lucky\agent_work\1\s" -Properties Configuration=Release
MSBuild auto-detection: using msbuild version '14.0' from 'C:\Program Files (x86)\MSBuild\14.0\bin'.
Please specify a nuspec or project file to use.
Unexpected exit code 1 returned from tool NuGet.exe
Finishing task: NuGetPackager
Task NuGetPackager failed. This caused the job to fail. Look at the logs for the task for more details.
According to the error info:
Please specify a nuspec or project file to use. Unexpected exit code 1
returned from tool NuGet.exe
You may specified a wrong argument in nuget package task ,please double check you have followed below requirements:
Specify .csproj files (for example, **\*.csproj) for simple projects. In this case:
The packager compiles the .csproj files for packaging.
You must specify Configuration to Package (see below).
You do not have to check in a .nuspec file. If you do check one in, the packager honors its settings and replaces tokens such as $id$ and
$description$.
Specify .nuspec files (for example, **\*.nuspec) for more complex projects, such as multi-platform scenarios in which you need to
compile and package in separate steps. In this case:
The packager does not compile the .csproj files for packaging.
Each project is packaged only if it has a .nuspec file checked in.
The packager does not replace tokens in the .nuspec file (except the element, see Use build number to version package,
below). You must supply values for elements such as and
. The most common way to do this is to hardcode the
values in the .nuspec file.
Please double check your arguments , more details please refer this tutorial-- Pack NuGet packages.
Besides you could also enable verbose debug mode by adding system.debug=true to get a more detail build log info for troubleshooting.

Restore nuget packages in msbuild 15 project

I'd like to restore the nuget packages from a private feed (vsts internal feed) in a solution consisting of msbuild 15 projects, and subsequently build (and pack) the projects.
I'm using the VS 2017 hosted agent which I need to build.
I've tried restoring with msbuild with (the deprecated) package restore enabled. This results in no packages being restored. The relevant part of the logs:
2017-04-03T12:21:23.5543508Z ##[warning]The 'Restore NuGet Packages' option is deprecated. To restore NuGet packages in your build, add a NuGet Installer task to your build definition.
2017-04-03T12:21:23.5803410Z ##[command]"C:\LR\MMS\Services\mms\TaskAgentProvisioner\Tools\agents\2.115.0\externals\nuget\NuGet.exe" restore "C:\a\1\s\mysolution.sln" -NonInteractive
2017-04-03T12:21:24.5231560Z MSBuild auto-detection: using msbuild version '4.0' from 'C:\Windows\Microsoft.NET\Framework\v4.0.30319'.
I've tried restoring with the nuget installer task. This fails with
2017-04-03T12:21:05.3231625Z [command]C:\a_tasks\NuGetInstaller_333b11bd-d341-40d9-afcf-b32d5ce6f23b\0.2.29\node_modules\nuget-task-common\NuGet\3.5.0\NuGet.exe restore -NonInteractive C:\a\1\s\mysolution.sln -Verbosity Detailed -msbuildversion 15
2017-04-03T12:21:07.5100892Z NuGet Version: 3.5.0.1938
2017-04-03T12:21:07.8293660Z System.AggregateException: One or more errors occurred.
---> NuGet.CommandLine.CommandLineException: Failed to load msbuild Toolset
---> System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Build, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
note that I pass in msbuildversion -15 as additional argument, but it seems nuget tries to load msbuild 14.
I've tried restoring with the dontnet cli dotnet restore. This fails with
2017-04-03T12:21:08.3424716Z [command]C:\Program Files\dotnet\dotnet.exe restore C:\a\1\s\path\to\my\csproj
2017-04-03T12:21:12.8146350Z Restoring packages for C:\a\1\s\path\to\my\csproj...
2017-04-03T12:21:12.8146350Z C:\Program Files\dotnet\sdk\1.0.0\NuGet.targets(97,5): error : Unable to load the service index for source https://myvstsaccount.pkgs.visualstudio.com/_packaging/Toolsfeed/nuget/v3/index.json. [C:\a\1\s\path\to\my\csproj]
2017-04-03T12:21:12.8146350Z C:\Program Files\dotnet\sdk\1.0.0\NuGet.targets(97,5): error : Response status code does not indicate success: 401 (Unauthorized). [C:\a\1\s\path\to\my\csproj]
2017-04-03T12:21:12.8176375Z ##[error]Dotnet command failed with non-zero exit code: 1.
The nuget.config in my solution directory is
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="VSTS Tools Feed" value="https://myvstsaccount.pkgs.visualstudio.com/_packaging/Toolsfeed/nuget/v3/index.json" />
</packageSources>
<apikeys>
<add key="https://myvstsaccount.pkgs.visualstudio.com/_packaging/Toolsfeed/nuget/v3/index.json" value="<A PAT generated from an account with access to the feed>" />
</apikeys>
</configuration>
and the logs of the tasks show that the config is used.
Locally package restore works fine from VS, or with the nuget cli of nuget 4.0.
What task should I use to restore packages for msbuild 15 projects, and how can I configure authentication?
Restoring nuget packages defined as PackageReference elements in csproj project definitions requires nuget 4.0, which isn't included on the hosted build agents.
You can work around this restriction by including the nuget 4.0 binary in your source control tree, and referring to that binary within the package restore task as a custom NuGet version.
For example, when you include the nuget 4.0 binary in a file called nuget4.0.exe in the root directory of your source tree, you can specify the path as $(Build.SourcesDirectory)/nuget4.0.exe.
And there is a relate question here for you to refer.

Run a command in ccnet.config

I am trying to run the nuget command that I would normally set in the projects post build $(ProjectDir)nuget\pack.bat $(ProjectDir) $(TargetDir) $(ConfigurationName) $(SolutionDir) to run instead in the ccnet.config on a successful build. What I have does not seem to be running at all.
<exec>
<Target>
<executable>cmd</executable>
<buildArgs>/C c:\build\project\nuget\pack.bat c:\build\project\ c:\build\project\bin\nuget\ Nuget c:\build\project\ /M</buildArgs>
</Target>
</exec>
Edit
Figured it out partially. Needed to make sure I was pointing to <executable>c:\Windows\System32\cmd.exe</executable> and not using cmd.