How to run dotnet test on VSTS with custom NuGet feed? - continuous-integration

We have a project with a dependency on a custom NuGet feed (also hosted in VSTS).
I'm trying to put together a new phase to generate code coverage reports, as in this blog post. My new phase looks like this:
And is made up of the following steps:
.NET Core Tool Installer - use SDK 2.0.0
dotnet restore with my custom feed selected in the "Use packages from this VSTS/TFS feed" drop-down
dotnet test with the relevant arguments to collect code coverage
A custom step using ReportGenerator
A step to publish the results
The problem is that dotnet test insists on trying to restore the packages itself. As I can't find a way to tell it to use a custom feed, it fails when trying to restore these packages:
D:\a\1\s\MyProject\MyProject.csproj : error NU1101: Unable to find package My.Package. No packages exist with this id in source(s): Microsoft Visual Studio Offline Packages, nuget.org
My main build process works fine and is able to restore the package from the custom feed. The difference is that uses the Visual Studio (i.e. not dotnet) versions of the commands:
What's the right way to handle this?
Do I need to find some way to tell dotnet test about my custom feed?
Or (given that I'm running restore immediately prior) do I need to persuade it to skip the restore altogether?

In case anyone else has this problem, I'm sorry to say our route to resolution was to merge the two repos, effectively negating the need to use the private Nuget feed.
We did have a bit of back and forth with a rep from MS, but didn't get to the bottom of it.

I had similar problem with dotnet test and custom nuget feed.
The solution was using two steps:
dotnet restore --source (my feed sources)
dotnet test --no-restore
See Implicit restore

What's the right way to handle this?
In step dotnet restore, make sure field Path to project(s) specifies all relevant projects. (It's easy to forget a project and that would result in the behavior you experience.) For instance, you can specify the value **/*.csproj. If you do this correctly, other steps such as dotnet test should not even try to restore packages since they have already been restored.
Do I need to find some way to tell dotnet test about my custom feed?
No (assuming step dotnet restore has already restored the packages)
Or (given that I'm running restore immediately prior) do I need to persuade it to skip the restore altogether?
No. It will automatically skip restoring (assuming step dotnet restore has already restored the packages)

I had the same error on a self hosted build agent. Once I changed the star syntax (get latest version) in the project file to a fixed version the problem went away. I am bit sad that I cant use the version syntax.

Related

TeamCity Visual Studio Build doesn't find package reference packages

I have a Teamy City Build Server and wanted to migrate my solution piece by piece to Package Reference. Unfortunately it seems that it doesn't find the references / packages for those project I already moved or reacreated with package reference. The packages are restored correctly as I see them in the global .nuget\packages folder. Also I can build locally without any issues.
Funny enough, I have some other smaller projects which do work correctly with package reference on teamcity.
TeamCity Version: 2019.2
NuGet: 5.4
I also tried to add a .NET CLI Task with a restore command, but that didn't change anything aswell.
NuGet Installer Step:
dotnet restore step:
In the end I create a new pipeline and reconfigured all the steps from scratch instead of copy an existing pipline and now it works. seems there was some issue somewhere attached to those existing pipelines.
After an entire day of trying to fix this problem I finally found the cause.
In the parameters of the build configuration in TeamCity there was a parameter called "system.VisualStudioVersion" with its value set to "11.0". I changed the value to "16.0", and this fixed the problem for me.
This might explain the solution of NPadrutt, assuming he had the variable set in that particular build configuration. Recreating his build configuration would then result in a new build configuration without the bad parameter, fixing the problem for him. But in my situation the parameter was inherited from the root project, so recreating the build configuration wouldn't have fixed it for me.

Octopus: Override /p:RunOctoPack=true in packages.config

We have a Mainline build versioned "x.0.0.r" where we publish a web service using octopus. Our branches are versioned "x.y.z.r" for specific releases. We DO NOT want to publish this web service when building from a branch.
We are using TFS: 2013 xaml build def; msbuild args: "... /p:RunOctoPack=true ..."
Short of setting /p:RunOctoPack=false or removing the OctoPack arguments from the branch build definition, is there any other way to NOT run Octopus? Perhaps in the packages.config file, to say if the version is NOT ".0.0." set "\p:RunOctoPack=false"?
We have missed removing this parameter when branching and cloning the build def and have mistakenly published the web service from the branch a few times. Would like to avoid this going forward.
Thanks,
tom
The deployments you describe are a bit confusing. I think you are wanting to deploy all versions tagged with version 18.x.y.z and not deploy any other version numbers.
Using Channels in Octopus would allow you to achieve this, without adding logic into your build process.
In your deployment process in Octopus, you would have a step that is deployment of your application. This is the one that you only want run when you are deploying version 18.x.
In the Channels section, add a channel and create a version rule for the channel. The package step will be the deployment step created earlier, and the version range will be something like [18.0.0,18.999.999.999)
The Version Rule Design screen gives you the ability to add sample version numbers to test your version expression.
This means that all deployments of version 18 will run the package step, and all others will skip it.
You can also get additional help via the Support channels

How to remove prerelease designation on nuget package?

I'm looking on creating NuGet packages as part of my CI builds. My intent is to be able to deploy the final application for testing, and once passed, allow that build to be promoted to a release version by removing the -prerelease designation. How can I take an existing NuGet prerelease package and convert it to a non prerelease?
I wonder if the package contain the hash file that is causing an issue. I think your only choice is to generate a new package.
Just open the nupkg file in Package Explorer and edit the version number.
I have done that many times to covert a -rc to production.
Works fine

TFS Team Build with VSO - Git Commit/Push files that have been altered by the build process

I have created a build definition that uses the Default Template(GitTemplate.12.xaml). I have a Pre-Build Script that updates the version numbers for all of the assemblies in the build.
I would like to be able to commit and push the files that have been altered by the build definition to the git repository.
I have tried doing this using a PowerShell script but was not able to do this because Git with VSO requires that you pass in user credentials.
I have downloaded the template to see if I can customise it to complete this task but can see no obvious way of solving my problem.
My next step will be to investigate writing a custom piece of code that can be called by the template.Just wanted to find out before I delve into this any deeper if I am wasting my time.
I am using VSO and VS2013.
Does anybody have a solution to my problem?
You should not commit those changes as it allows a developer to build an identical version numbered assembly locally.It is not a good practice to push the results back into Source Control.
You should set all of your assemblyinfo.* files to 0.0.0.0 and push. Then the only way for your assemblies to get a "good" version number is through the build process.
If you do want to go ahead you will need to authenticate using the "alternative" credentials that you can get from your profile page.

How to checkin the output of a project/solution (dll) post a successful build in TFS2010

Just wondering on the recommended process of checking in an output of a project or solution post a successful build.
For example the Build relates to a common library. Post a change I want that to be checked in to a known location so other solutions can reference.
Some examples might be
Custom Workflow activities
Invoking TF exe directly
I would not check an output in. Instead, I would move it to a well-known location, probably a file share.
I don't do this currently but plan to investigate NuGet as a solution to this scenario. MSDN has some articles showing how to incorporate NuGet into your projects and host a private gallery of your own NuGet packages. MSDN has examples of a build that compiles your common code and then packages it and updates it into your private NuGet gallery. Then in your projects you would consume the NuGet package of the common library you wish to use.
Main MSDN article describing this:
http://msdn.microsoft.com/en-us/magazine/hh781026.aspx
Other resources:
http://nuget.org/
http://nugetter.codeplex.com/
Have a look at this post from Ewald Hofman, it updates certain files and checks them in using a custom activity. You could use the same process. But this involves customizing the build process template and deploying custom build activities to all build agents.
But you might also want to investigate the free AIT Dependency Manager which can download the latest specific version (can filter on build outcome or quality) of one build from the buildserver as reference to another build (also inside Visual Studio). This is a lot more flexible than constantly checking in the build output and allows you to have your dev branch to always get the latest (unstable) version, but your release branch to always get the latest well tested and approved version.

Resources