How to have GoCD restore NuGet packages when building solution

338 views Asked by At

I am trying to learn how to use Go CD to implement continuous integration into my company's workflow. I'm using GitHub for my source control and have my pipeline set up to monitor the repository for changes and attempt to rebuild whenever there's a change. All that is working fine. Now I'm trying to add unit tests to the pipeline and can't get the unit test project to build.

This is the config xml for my build command:

<exec command="%Windir%\Microsoft.NET\Framework64\v4.0.30319\MsBuild.exe" workingdir="UnitTest">
    <arg>/T:rebuild</arg>
    <arg>/P:Configuration=Release</arg>
    <arg>/m</arg>
    <runif status="passed" />
</exec>

This is the relevant part of the error that I'm getting:

The missing file is ..\packages\MSTest.TestAdapter.1.1.18\build\net45\MSTest.TestAdapter.props

The unit test project uses some NuGet packages, so it needs these files to build properly, but they are not in the working directory for GoCD. I added a job to my pipeline before trying to build the unit tests that restores the NuGet packages to the location specified in the error message. Here is the config xml for my restore nugget command:

<exec command="C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\ReadyRoll\Octopack\build\NuGet.exe" workingdir="UnitTest">
    <arg>restore</arg>
    <arg>packages.config</arg>
    <arg>-PackagesDirectory</arg>
    <arg>..\packages</arg>
    <runif status="passed" />
</exec>

When I re-ran the pipeline and monitored the working directory, I see the NuGet files get created when the "restore" step is run, however building the unit test project deletes the files and I still get the error.

I thought this was because I was using /T:rebuild in my MSBuild command, but it still deleted the files when I changed it to /T:build.

Can anyone give me a tip on how add a job to my pipeline that builds a project using NuGet packages? I thought about adding the "NuGet.exe restore" command to the project file, but I couldn't figure out how to do it (or if it can be done?).

Thanks in advance!

1

There are 1 answers

0
starx207 On

I figured out what I was doing wrong. I set up the build and restore commands in separate jobs, I needed to make them both tasks in the same job. I did that, and it worked.

I think this has something to do with how GoCD checks out the material for each job? But since I'm so new to this (and may not be right about the reasons), I'm not going to speculate about why this changed caused it to work.

If anyone knows the reason, I'd be happy to know.