dotnet 构建到特定框架版本 [英] dotnet build to specific framework version

查看:74
本文介绍了dotnet 构建到特定框架版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是前几天刚刚发布的最新 .NET SDK(1.0.1,安装自 https://dotnetcli.blob.core.windows.net/dotnet/Sdk/1.0.1/dotnet-dev-debian-x64.1.0.1.tar.gz) 使用dotnet publish"构建项目.由于这个问题范围之外的原因,我正在尝试构建应用程序,以便它们在框架的较旧版本(1.0.3 和 1.1.0,而不是最新的 1.0.4 和 1.1.0)上运行.

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).

如果我构建一个指定 netcoreapp1.1 的项目,它将无法在仅安装了 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.

看起来我可以在每个项目的基础上在我的 csproj 中指定 <RuntimeFrameworkVersion>1.1.0</RuntimeFrameworkVersion>,但是有什么方法可以配置 dotnet 以便针对 netcoreapp1.1 默认针对 1.1.0?

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?

推荐答案

你说得对,当你只指定netcoreapp1.1时,默认是针对你的应用以最新的运行时为目标:1.1.1.这是进行更改的 PR.就像您提到的,这意味着您的应用程序不再运行在只有 1.1.0 的机器上.

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.

有什么办法可以配置 dotnet,以便默认针对 netcoreapp1.1 的目标是 1.1.0?

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. 调用dotnet publish时,可以传入MSBuild参数.所以你可以说 dotnet publish -c Release/p:RuntimeFrameworkVersion=1.1.0
  2. 您可以在要为其设置默认属性的所有 .csproj 文件上方添加一个 Directory.Build.props 文件.这个 .props 文件将自动导入到它下面的所有 .csproj 文件中.您可以在其中设置常用属性:

  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.

这篇关于dotnet 构建到特定框架版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆