繁体   English   中英

带有Microsoft.Extensions.DependencyInjection的.NET Framework类库

[英].NET Framework Class Library with Microsoft.Extensions.DependencyInjection

我有一个.NET Framework(4.5.2)类库,我想使用Microsoft.Extensions.DependencyInjection,因为我们正在单独开发一个ASP.NET Core应用程序。

我使用nuget安装它,当我使用Visual Studio构建时它工作正常但是在TeamCity构建代理上尝试使用MSBuild构建它给了我很多这样的:

MyClass.cs(32, 26): error CS0012: The type 'IServiceProvider' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.ComponentModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
MyClass.cs(33, 31): error CS0012: The type 'IDisposable' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
MyClass.cs(33, 31): error CS1061: 'IServiceScope' does not contain a definition for 'Dispose' and no extension method 'Dispose' accepting a first argument of type 'IServiceScope' could be found (are you missing a using directive or an assembly reference?)
MyClass.cs(34, 10): error CS0012: The type 'IDisposable' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
MyClass.cs(34, 10): error CS0012: The type 'IServiceProvider' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.ComponentModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
MyClass.cs(35, 10): error CS0012: The type 'IDisposable' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
MyClass.cs(35, 10): error CS0012: The type 'IServiceProvider' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.ComponentModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
MyClass.cs(36, 51): error CS0012: The type 'IDisposable' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
MyClass.cs(36, 51): error CS0012: The type 'IServiceProvider' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.ComponentModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
MyClass.cs(36, 30): error CS0012: The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

一些nuget包(如Microsoft.Extensions.DependencyInjection本身)没有单独的net452程序集,只有netstandard1.0或netstandard1.1。 这可能是问题吗? 我在构建服务器上安装.NET Core SDK无效。

我遇到了同样的问题,但在使用NuGet Installer作为构建步骤后,我的所有问题都得到了解决。

在构建项目之前,您需要做一件事 - 只需添加一个构建步骤并选择Runner type作为NuGet Installer

您可以从此屏幕截图中查看:

在此输入图像描述

事实证明我错过了.NET Framework 4.5.2 Developer Pack,奇怪的是我所有其他解决方案都没有它。

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM