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

标签 c# .net dependency-injection msbuild

我有一个 .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 type 作为 NuGet Installer

您可以从这个截图中查看:

enter image description here

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

相关文章:

c# - Azure物联网中心: Can't call direct method using AMQP protocol

java - 服务定位器与依赖注入(inject)

c# - 使用依赖注入(inject)是否需要使用要注入(inject)的接口(interface)而不是具体类?

c# - container.RegisterWebApiControllers(GlobalConfiguration.Configuration) 导致 InvalidOperationException

c# - 如何使用 ServiceStack.Net 实现客户端身份验证

c# - 如何将 UTF-8 转换为 HTML 实体中的文本?

c# - 在 IronPython 中使用 C# 代码

c# - Azure 数据库同步

.net - 如何使自定义 WCF 错误处理程序返回带有非 OK http 代码的 JSON 响应?

C# 可移植 IDE 和编译器 - 它需要的一切都需要在 USB 闪存驱动器上