简体   繁体   English

在引用NetStandard20程序集的Framework461解决方案上使用MSBUILD

[英]Using MSBUILD on a Framework461 solution that references a NetStandard20 assembly

I'm not even sure if what I'm trying to do is possible... 我什至不确定我想做的事情是否可能...

Sample code: here 示例代码: 此处

Basically, I've built a netstandard20 class library which according to the .NET implementation support list should be compatible with a framework461 project (providing you have the .NET Core 2.0 SDK). 基本上,我已经建立了一个netstandard20类库,根据.NET实现支持列表,该库应该与framework461项目兼容(前提是您拥有.NET Core 2.0 SDK)。

在此处输入图片说明

I can build the netstandard20 class library no worries and get the DLL back (it's included in the sample code). 我可以毫无后顾之忧地建立netstandard20类库,并重新获得DLL(它包含在示例代码中)。

This is where the problem starts, when attempting to run msbuild .\\netstandard_test.sln to build the framework461 project I get a whole bunch of (what I believe to be misleading) errors about 'netstandard' not being referenced (which it is). 这是问题开始的地方,当尝试运行msbuild .\\netstandard_test.sln来构建framework461项目时,我收到一堆关于(未误)“ netstandard”的错误(我认为是误导性的)。

在此处输入图片说明

However, if I run dotnet build (or build from VS2017) everything works as expected. 但是,如果我运行dotnet build (或从VS2017构建),则一切正常。

I've tried importing various versions of NetStandard, NetStandard.Library and NetStandard.Library.Framework, as well as referencing Microsoft.DotNet.BuildTools but that didn't appear to help. 我尝试导入各种版本的NetStandard,NetStandard.Library和NetStandard.Library.Framework,以及引用Microsoft.DotNet.BuildTools,但这似乎没有帮助。

Is there any way to build this using msbuild? 有什么方法可以使用msbuild来构建它吗? We have a monolithic build and deployment process and I'd rather not have to change it if it can be avoided. 我们有一个整体的构建和部署过程,如果可以避免的话,我宁愿不必更改它。 Who knows what else would go wrong! 谁知道还有什么地方会出错!

To build with .NET Core or .NET Standard you need to use the dotnet msbuild command from the .NET Core SDK rather than just plain msbuild . 要使用.NET Core或.NET Standard进行构建,您需要使用.NET Core SDK中的dotnet msbuild命令 ,而不仅仅是简单的msbuild

dotnet msbuild .\netstandard_test.sln /p:Configuration=Release

This will also work with .NET Framework 4.6.1 (and older versions). 这也将与.NET Framework 4.6.1(和较旧版本)一起使用。

Do note that Microsoft has provided install scripts to make installing the .NET Core SDK painless on continuous integration servers. 请注意,Microsoft提供了安装脚本,以使在连续集成服务器上轻松安装.NET Core SDK变得容易。

You need to use a recent 15.* version (currently 15.5.*) of MSBuild and make sure that the "Cross platform development" workload is installed in visual studio. 您需要使用MSBuild的最新15. *版本(当前为15.5。*),并确保Visual Studio中安装了“跨平台开发”工作负载。 This adds the required components to locate the .NET Core SDK, which contains MSBuild SDKs like Microsoft.NET.Sdk or Microsoft.NET.Sdk.Web used by .NET Standard and .NET Core projects. 这将添加所需的组件以定位.NET Core SDK,其中包含MSBuild SDK,如.NET Standard和.NET Core项目使用的Microsoft.NET.SdkMicrosoft.NET.Sdk.Web

You can then use msbuild from the developer command prompt to build these projects. 然后,您可以在开发人员命令提示符下使用msbuild来构建这些项目。 I suggest adding /restore (msbuild >= 15.5.*) to make sure that a NuGet restore happened for sdk-based projects. 我建议添加/restore (msbuild> = 15.5。*),以确保基于sdk的项目发生NuGet还原。

Since VS 2017 does not install a "global" version of MSBuild, be sure to use the version of MSBuild installed in the VS 2017 folders (check with msbuild /version or where msbuild ). 由于VS 2017未安装MSBuild的“全局”版本,因此请确保使用VS 2017文件夹中安装的MSBuild版本(请使用msbuild /versionwhere msbuild )。

dotnet msbuild has limitations when you use .resx files containing file references or non-string properties. 当您使用包含文件引用或非字符串属性的.resx文件时, dotnet msbuild具有局限性。 Also, it does not support COM references or building strong named assemblies. 另外,它不支持COM引用或构建强命名程序集。 If you need any of these features, use msbuild (VS 2017) over dotnet msbuild (.NET Core CLI) 如果需要这些功能中的任何一个,请通过dotnet msbuild (.NET Core CLI)使用msbuild (VS 2017)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 netstandard20 中的 System.Data.Linq - System.Data.Linq in netstandard20 来自netstandard 2.0的参考.net461程序集 - Reference .net461 assembly from netstandard 2.0 NETStandard20无法还原Microsoft.Azure.KeyVault.Core - Microsoft.Azure.KeyVault.Core doesn't Restore with NETStandard20 如何使用 CMake 为 Visual Studio 解决方案设置程序集引用? - How to set assembly references for Visual Studio solution using CMake? 基于解决方案的条件程序集引用 - conditional assembly references based on solution 多目标net461和netstandard-即使在net461使用者中也需要netstandard依赖项 - Multi targetting net461 and netstandard - netstandard dependencies required even in net461 consumer Microsoft Bot框架程序集参考 - Microsoft Bot framework assembly references 将netstandard2.0库加载到net461项目 - Load in netstandard2.0 libraries to net461 project 通过 PowerShell 使用 msbuild 为 DotNet Framework 4.7 项目指定程序集版本 - Specify the assembly version for a DotNet Framework 4.7 project using msbuild via PowerShell 如何使用Resharper在解决方案中的其他项目中找到C#组装项目参考? - How to find C# Assembly Project References in other Projects within Solution using Resharper?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM