我有一个.NET Framework(4.5.2)类库,在我们分别开发ASP.NET Core应用程序时,我想将其与Microsoft.Extensions.DependencyInjection一起使用。

我使用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类型作为NuGet安装程序即可。

您可以从以下屏幕截图中进行检查:

c# - 带有Microsoft.Extensions.DependencyInjection的.NET Framework类库-LMLPHP

关于c# - 带有Microsoft.Extensions.DependencyInjection的.NET Framework类库,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42114479/

10-10 15:25