How to create application that targets both .Net 4.6.1 and Core RC2?
See original GitHub issueAssume 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:
- Created 7 years ago
- Comments:10 (4 by maintainers)
Top GitHub Comments
Can someone confirm - is this the same for
NETStandard.Library
too? i.e does it have to go under the frameworknetstandard1.5
rather than in dependencies directly?@roshantarudkar have you solved your issue above? i am also experiencing this error and cannot find fix to it,