question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to create application that targets both .Net 4.6.1 and Core RC2?

See original GitHub issue

Assume that I’m trying to create a very simple ASP.NET Core RC2 application that takes advantage of a .Net Framework assembly, but can also run without it. The code would look something like this:

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;

#if NET461
using System.DirectoryServices.AccountManagement;
#endif

namespace CoreWebApplication
{
    public class Startup
    {
        public void Configure(IApplicationBuilder app)
        {
            app.Run(async context =>
            {
#if NET461
                var message = UserPrincipal.Current.ToString();
#else
                var message = "Unknown";
#endif
                await context.Response.WriteAsync(message);
            });
        }
    }
}

Here System.DirectoryServices.AccountManagement.UserPrincipal is the type from .Net Framework.

What is the right way to write project.json to make this work?

My assumption was that it would be:

"dependencies": {
  "Microsoft.NETCore.App": {
    "version": "1.0.0-rc2-3002702",
    "type": "platform"
  },
  "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-rc2-final"
},

"frameworks": {
  "net461": {
    "frameworkAssemblies": {
      "System.DirectoryServices.AccountManagement": "4.0.0.0"
    }
  },
  "netcoreapp1.0": {}
},

But this fails on dotnet build with:

error NU1002: The dependency System.Runtime.Loader 4.0.0-rc2-24027 does not support framework .NETFramework,Version=v4.6.1.

What I tried next is to move the dependency on Microsoft.NETCore.App to just netcoreapp1.0:

"dependencies": {
  "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-rc2-final"
},

"frameworks": {
  "net461": {
    "frameworkAssemblies": {
      "System.DirectoryServices.AccountManagement": "4.0.0.0"
    }
  },
  "netcoreapp1.0": {
    "dependencies": {
      "Microsoft.NETCore.App": {
        "version": "1.0.0-rc2-3002702",
        "type": "platform"
      }
    }
  }
},

To my surprise, this worked, both with dotnet run -f net 461 and dotnet run -f netcoreapp1.0. And now that I think about it, Microsoft.NETCore.App only being compatible with netcoreapp1.0 kind of makes sense.

My questions are:

  • Is this the right way to do it?
  • Is it sensible to require this kind of unobvious (at least to me), undocumented (at least I didn’t find any documentation on it) project.json manipulation for this?

(This question is to satisfy my curiousity, not any actual requirements. It was inspired by this SO question)

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
dazinatorcommented, Jun 5, 2016

Can someone confirm - is this the same for NETStandard.Library too? i.e does it have to go under the framework netstandard1.5 rather than in dependencies directly?

0reactions
sureshKintacommented, Jul 14, 2017

@roshantarudkar have you solved your issue above? i am also experiencing this error and cannot find fix to it,

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Target netcoreapp and net461 from ASPNET Core
If you wish to have one app target multiple frameworks, you can do so by first adding the new framework to the list...
Read more >
Multi-targeting .net core 2.2 with .net 4.6.1
You only have package references present for .NET Core. You should have an item group for each of the following if they apply:....
Read more >
Announcing .NET Core RC2 and .NET Core SDK Preview 1
NET Core development by installing the .NET Core SDK. The SDK includes enough software to build an app. The SDK gives you both...
Read more >
Cross-platform targeting for .NET libraries
The best way to call framework-specific APIs is using multi-targeting, which builds your project for many .NET target frameworks rather than for ...
Read more >
Please stop lying about .NET Standard 2.0 support!
We currently support .NET 4.6.1, .NET Standard 2.0, and .NET Core 3.1, which means we can run on any application that targets .NET...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found