15
votes

I'm trying to build a .net core 1.1 project on vsts. The project is developed in vs2017 and it uses the csproj instead of project.json. I have tried multiple options to build id on vsts with the hosted agents (windows and linux).

i have tried the following build steps

Visual studio build

Set to use vs 2017 but i get a warning "Visual Studio version '15.0' not found. Looking for the latest version." And then i get errors because it cant include .net core packages.

.NET Core (PREVIEW)

Cant find project.json. When i set it to use csproj file it gives an error "The file type was not recognized"

Command build step

I tried to run the commands with command build steps. "dotnet build" gives the error that it cant find the project.json file.

Anyone building dotnet 1.1 with csproj on vsts that can help me how to do it?

6
Same here. Will get back to you if I find a solution.Wiebe Tijsma
.Net CLI for .csproj project file format and msbuild engine is still in preview version, it will be available in feature. It's easy to setup a on premise build agent, you can use on premise build agent now.starian chen-MSFT

6 Answers

20
votes

In Visual Studio Team Services, go to Build & Release > Builds and click Edit for the build definition you want to update

enter image description here

Navigate to the Options tab, change Default agent queue to Hosted VS2017, and save.

Hosted VS2017

4
votes

You can download dotnet SDK manually and run dotnet build from command line. So it could be something like this:

  1. Inline PowerShell step (I've used Inline Powershell extension by Peter Groenwegen):

    Invoke-WebRequest https://go.microsoft.com/fwlink/?linkid=837977 -OutFile $(System.DefaultWorkingDirectory)\dotnet.zip
    
  2. Extract files step:

    From: $(System.DefaultWorkingDirectory)\dotnet.zip
    To: $(System.DefaultWorkingDirectory)\dotnet
    
  3. Restore packages:

    $(System.DefaultWorkingDirectory)\dotnet\dotnet.exe restore
    

... and so on

But there is some limitation — you still haven't had .Net Core 1.1 installed at build agent machine so some features may not work. At least dotnet test will fail because it requires appropriate .Net Core runtime. Maybe some other features as well.

2
votes

extending on @Nikolay Balakin's answer, it's true the .NET Core projects using *.csproj are not supported yet.

You can work around this by installing the latest .NET core on the hosted build environment yourself.

This will allow running dotnet restore, dotnet build, dotnet publish, and dotnet test.

Use the Inline powershell extension to run a script. You can link to a script, or paste the text in inline. I am running a script which is checked in to the project.

enter image description here

It seems each powershell script will be run in it's own environment, so paths etc. will not persist between scripts, so the installation steps and the build steps need to be combined into one script.

You need to copy the dotnet installation script from github and add your own build commands to the end.

I know this is not a long term solution, but we justified it by assuming the VSTS will in the near future support the *.csproj files, and we will convert to use the official build task.

Here is an example powershell script, showing the last line of the installation script, and the custom build commands on the end.

...
...
Say "Installation finished"
# this is the end of the downloaded script, add your steps after here.

Say "Running dotnet restore AdminPortal\AdminPortal.csproj"
dotnet restore AdminPortal\AdminPortal.csproj

Say "dotnet publish AdminPortal\AdminPortal.csproj --configuration Release"
dotnet publish AdminPortal\AdminPortal.csproj --configuration Release

Say 'Zipping publish file'

$source = $env:BUILD_REPOSITORY_LOCALPATH
$source = $source + '\AdminPortal\bin\Release\net461\publish'

$destination = $env:BUILD_REPOSITORY_LOCALPATH
$destination = $destination + '\AdminPortal\bin\Release\net461\publish.zip'

Add-Type -assembly "system.io.compression.filesystem"
[io.compression.zipfile]::CreateFromDirectory($source, $destination)

Say "Publish finished"

dotnet test "AdminPortal.Tests\AdminPortal.Tests.csproj"

Say "Test finished"

exit 0
1
votes

According to this issue .NET Core projects using *.csproj files are not supported yet:

https://github.com/Microsoft/vsts-tasks/issues/3311

"if you are using hosted agent - then the tooling there works only with project.json files"

I've tried the tutorials here, but they also seem to be outdated (I couldn't even get tfx-cli installed on my machine): http://mattvsts.blogspot.nl/2016/11/start-building-aspnet-core-11-with-tfs.html

0
votes

In my case, I have a .NET Core web app and four library projects, all targeting the full framework since I'm using EF 6.

I tried all of the suggestions here and none of them worked. Building with Visual Studio Build on Hosted Agent 2017 does build the project, but doesn't output any binaries. And all the options above did build as well but didn't generate the output files.

Reading around I found the only way to get the output files was by running dotnet publishbut this generates a build error because nuget isn't restoring well the packages and msbuild can't find them. After being tired of trying to make it work during a whole day, casually I enabled the "Restore Nuget Packages" on the VS Buid task, and though it says it's deprecated, that seems to have solved my isse.

0
votes

In VSTS you need to add netcore exists as a demand.

  1. Go to your build definition
  2. Click on the options tab position of option tab
  3. Add the demand netcore exists how to input the demand netcore exists