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

时间:2017-02-08 13:29:32

标签: c# .net dependency-injection msbuild

我有一个.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无效。

2 个答案:

答案 0 :(得分:1)

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

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

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

enter image description here

答案 1 :(得分:0)

原来我错过了.NET Framework 4.5.2开发包,很奇怪我没有它就能很好地构建所有其他解决方案。