4
votes

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?

1
What IDE/version/language are you using?JamesFaix
No IDE, all text files, doing everything via dotnet 1.0.1 on the command line. C#.nlawalker
What do you mean by "1.0.3 and 1.1.0". To what do the two versions refer? Are you talking about the LTS vs Current versions of the runtime? Or are you talking about the runtime version and SDK version?Shaun Luttin
@ShaunLuttin I'm referring to specific patch versions of the LTS (1.0) and current (1.1) versions of the runtime.nlawalker

1 Answers

5
votes

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.