Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual studio team services build .net core 1.1

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?

like image 612
Tom Avatar asked Jan 16 '17 10:01

Tom


3 Answers

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

like image 167
Matthew Steven Monkan Avatar answered Nov 16 '22 15:11

Matthew Steven Monkan


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.

like image 4
Mykola Balakin Avatar answered Nov 16 '22 14:11

Mykola Balakin


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
like image 2
jmc Avatar answered Nov 16 '22 13:11

jmc