3

I have a .NET Framework (4.5.2) class library that I'd like to use Microsoft.Extensions.DependencyInjection with as we're separately developing an ASP.NET Core app.

I installed it using nuget, it works fine when I build using Visual Studio but trying to build it using MSBuild on a TeamCity build agent gives me a lot of this:

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'.

Some of the nuget packages (like Microsoft.Extensions.DependencyInjection itself) don't have a separate net452 assembly and only netstandard1.0 or netstandard1.1. Could this be the issue? I installed the .NET Core SDK on the build server to no effect.

5
  • 1
    As expressed here and here, class libraries should not use any DI library. Commented Feb 8, 2017 at 14:10
  • The library exposes an abstract Topshelf service class that is then implemented in a Console app, analogous to how ASP.NET is in practice a library that uses DI. I'm doing it this way so we don't need to copy paste boilerplate into every service we make. Commented Feb 8, 2017 at 14:20
  • There are many downsides to such approach, especially when you make use of the .NET Core DI abstraction which is a Conforming Container. Commented Feb 8, 2017 at 14:22
  • @JussiKosunen - "I'm doing it this way so we don't need to copy paste boilerplate into every service we make." - Do you have a .config file for every service you make? Think of the composition root as another (in code) .config file. You wouldn't share a .config file between applications, so why would you share a composition root? Commented Feb 8, 2017 at 15:55
  • The composition root is in the service, nothing is added to the container in the library implicitly. The library only provides a framework and utilities to make the experience as close as possible to ASP.NET Core. I'm attempting to prioritise making the service implementer's work easier rather than fussing about which assembly the ioc container is instantiated in. Commented Feb 9, 2017 at 7:04

2 Answers 2

1

I was facing the same issue but after using NuGet Installer as a build step my all problems gets resolved.

Just you need to do one thing, before going to build your project - Just add one build step and select Runner type as NuGet Installer

You can check from this screenshots:

enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

In this case I had already done this. The required assemblies (System.ComponentModel and System.Runtime) don't come as dependencies through NuGet, rather require either Visual Studio or the Developer Pack to be installed.
0

Turns out I was missing the .NET Framework 4.5.2 Developer Pack, strange that all my other solutions built fine without it.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.