nlawalker
nlawalker

Reputation: 6514

dotnet build to specific framework version

I'm using the newest .NET SDK just released the other day (1.0.1, installed from https://dotnetcli.blob.core.windows.net/dotnet/Sdk/1.0.1/dotnet-dev-debian-x64.1.0.1.tar.gz) to build projects with "dotnet publish." For reasons outside of the scope of this question, I am trying to build applications so that they run on slightly older versions of the framework (1.0.3 and 1.1.0, as opposed to the newest 1.0.4 and 1.1.0).

If I build a project that specifies <TargetFramework>netcoreapp1.1</TargetFramework>, it won't run on a platform that only has version 1.1.0 installed.

It looks like I can specify <RuntimeFrameworkVersion>1.1.0</RuntimeFrameworkVersion> in my csproj on a per-project basis, but is there any way I can configure dotnet such that targeting netcoreapp1.1 targets 1.1.0 by default?

Upvotes: 5

Views: 6292

Answers (1)

Eric Erhardt
Eric Erhardt

Reputation: 2456

You are right, when you only specify <TargetFramework>netcoreapp1.1</TargetFramework>, the default is for your application to target the latest runtime: 1.1.1. Here's the PR that made the change. Like you mention, this means your application no longer runs on a machine with only 1.1.0 on it.

is there any way I can configure dotnet such that targeting netcoreapp1.1 targets 1.1.0 by default?

In my mind, you have two options:

  1. When you call dotnet publish, you can pass in MSBuild parameters. So you can say dotnet publish -c Release /p:RuntimeFrameworkVersion=1.1.0
  2. You can add a Directory.Build.props file above all the .csproj files that you want to default properties for. This .props file will automatically be imported in all the .csproj files below it. You can set common properties in it:

    <Project>
      <PropertyGroup>
        <RuntimeFrameworkVersion>1.1.0</RuntimeFrameworkVersion>
      </PropertyGroup>
    </Project>
    

Now all of your projects will get this property set automatically.

Upvotes: 6

Related Questions