在 MacOS 上构建需要 net461 的 dotnet SDK 项目的最简单方法 [英] Simplest way to build dotnet SDK project requiring net461 on MacOS
问题描述
我有一个 dotnet SDK .sln
(和一个 build.proj
)和 <TargetFrameworks>netcoreapp2.1;net461</TargetFrameworks>代码>.它使用 Visual Studio 和
dotnet build
在 Windows 上构建,但我也希望它构建尽可能多的其他地方.我需要在我的 README.md 中放入什么和/或我可以在项目文件中放入什么以使其在 Mac 上的 Rider 和/或 bash 上构建?
I have a dotnet SDK .sln
(and a build.proj
) with <TargetFrameworks>netcoreapp2.1;net461</TargetFrameworks>
. It builds on Windows using Visual Studio and dotnet build
, but I'd also like it to build as many other places as possible. What do I need to put in my README.md and/or what can I put in the project files to make it build on Rider and/or on from bash on a Mac?
推荐答案
(使用 .NET Core SDK)为 .NET 构建的最简单方法框架 TFM当使用 macOS 或 Linux 上运行时="nofollow noreferrer">.NET Core CLI,是利用 .NET Framework Targeting Pack Nuget Packages 来自 Microsoft(目前处于预览中):
(using .NET Core SDK) The simplest way to build for a .NET Framework TFM when running on either macOS or Linux using the .NET Core CLI, is to utilize the .NET Framework Targeting Pack Nuget Packages from Microsoft (currently in preview):
这些包支持在至少安装了 MSBuild 或 .NET Core SDK 的任何机器上构建 .NET Framework 项目.
These packages enable building .NET Framework projects on any machine with at least MSBuild or the .NET Core SDK installed.
为 .NET Framework 项目启用了以下方案和优势:
The following scenarios and benefits are enabled for .NET Framework projects:
- 无需管理员操作即可构建,以安装 Visual Studio 或 .NET Framework 目标包等先决条件.
- 在 .NET Core SDK 支持的任何操作系统上构建库.
- 构建基于 Mono 的项目.
您可以包含 Microsoft.NETFramework.ReferenceAssemblies 元包;或者只使用特定的包,在你的情况下 Microsoft.NETFramework.ReferenceAssemblies.net461.
You may either include the Microsoft.NETFramework.ReferenceAssemblies metapackage; or use just the specific package, which is in your case Microsoft.NETFramework.ReferenceAssemblies.net461.
将包添加到 *.csproj
或您的 Directory.Build.props
:
Add the package to the *.csproj
or your Directory.Build.props
:
<Project>
<ItemGroup>
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0" PrivateAssets="All" />
</ItemGroup>
</Project>
注意:PrivateAssets
属性控制哪些依赖资产将被消耗但不会流向父项目.请参阅 文档.
Note: The PrivateAssets
attribute controls which dependency assets will be consumed but won't flow to the parent project. See the docs.
使用 .NET 5 SDK(例如 5.0.100)不再需要这样做,它现在会自动将 PackageReference
添加到.NET Framework 的 ReferenceAssemblies.
This is no longer required using the .NET 5 SDK (e.g. 5.0.100), which will now automatically add the PackageReference
to the ReferenceAssemblies for .NET Framework.
这篇关于在 MacOS 上构建需要 net461 的 dotnet SDK 项目的最简单方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!