BrunoMartinsPro
BrunoMartinsPro

Reputation: 1856

Building .a NET Core project using Jenkins always references the latest installed SDK version

I'm running a "Build a Visual Studio project or solution using MSBuild" on Jenkins for several projects to generate nuget packages.

The MSBuild used is the latest Visual Studio Build Tools

The version of the .NET Core sdk used in the project is 1.0.4
Company.Core.csproj:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netcoreapp1.0</TargetFramework>
    <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
  </PropertyGroup>

</Project>

However while executing a build the used SDK version is always the latest SDK installed on the machine (2.x).

C:\Program Files\dotnet\sdk\2.1.400\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(198,5): 
error NETSDK1064: Package Microsoft.CSharp, version 4.0.1 was not found. 
It might have been deleted since NuGet restore. Otherwise, NuGet restore might have only partially completed, which might have been due to maximum path length restrictions. 
[C:\Workspaces\Company.Core\Company.Core.csproj]

After uninstalling the 2.1.400 SDK version i get the error:

C:\ProgramFiles\dotnet\sdk\1.1.10\Sdks\Microsoft.NET.Sdk\build\Microsoft.PackageDependencyResolution.targets(308,5): 
    error : Assets file 'C:\Workspaces\Company.Core\obj\project.assets.json' not found. Run a NuGet package restore to generate this file. [C:\Workspaces\Company.Core\Company.Core.csproj]

The installation used to support .net Core 1.0.4 was .NET Core 1.0.4 & 1.1.1 SDK 1.0.1 using the instructions:

Windows Server Hosting

If you are looking to host stand-alone apps on Windows Servers, the ASP.NET Core Module for IIS can be installed separately on servers without installing .NET Core runtime. You can download the Windows (Server Hosting) installer and run the following command from an Administrator command prompt:

DotNetCore.1.0.4_1.1.1-WindowsHosting.exe OPT_INSTALL_LTS_REDIST=0 OPT_INSTALL_FTS_REDIST=0

I also added RuntimeFrameworkVersion in the csproj that had no effect.

<RuntimeFrameworkVersion>1.0.4</RuntimeFrameworkVersion>^

global.json also gets ignored

{
  "sdk": {
    "version": "1.0.4"
  }
}

Upvotes: 0

Views: 3197

Answers (2)

omajid
omajid

Reputation: 15223

I think there's some confusion here. .NET Core consists of two almost separate components: the SDK and the Runtime. The SDK is used to build your code and the runtime is needed to run it.

They are versioned differently. For example, the latest SDK is 2.1.403, while the latest Runtime is 2.1.5.

A recent version of SDK can target any version of the runtime released before it. So, a 2.1.403 SDK can build applications that need 2.0 or 1.0 to run.

You can force a particular SDK to be used, by using the global.json file. You need to specify a version of the SDK that is already installed. dotnet new globaljson will generate something that you can edit the versions in. But you shouldn't need to do that. You can just use the latest SDK and ask it to build for an older runtime by setting the TargetFramework as you do.

If you do a dotnet restore, does the error NETSDK1064: Package Microsoft.CSharp, version 4.0.1 was not found. still stick around? The second error, Assets file 'C:\Workspaces\Company.Core\obj\project.assets.json' not found. Run a NuGet package restore to generate this file. backs this up. The project.assets.json is created by dotnet restore. Could you simply be missing that step?

Upvotes: 1

RQDQ
RQDQ

Reputation: 15579

It looks like you can specify the sdk version in a global.json file:

{
  "sdk": {
    "version": "1.0.4"
  }
}

Source: https://markheath.net/post/switching-between-netcore-sdk-versions

Upvotes: 1

Related Questions