.Net Core 1.0 has been released couple days ago, and i've started playing with it. I've created simple solution, with one project (class library => .NetStandard.Library) and second, console application (.NetCoreApp). The point is, console application has reference to library, but i cant use types form that library. Are those two frameworks incompatible? Am i missing something?
project.json for console application:
{
"version": "1.0.0-*",
"buildOptions": {
"emitEntryPoint": true
},
"dependencies": {
"ConsoleApplicationLibrary": "1.0.0-*",
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0"
}
},
"frameworks": {
"netcoreapp1.0": {
"imports": "dnxcore50"
}
}
}
project.json for library:
{
"version": "1.0.0-*",
"dependencies": {
"NETStandard.Library": "1.6.0"
},
"frameworks": {
"netstandard1.6": {
"imports": "dnxcore50"
}
}
}
I've figured it out, that it works, and code compiles, but visual studio still highlights types from library as unknown.
The most likely issue is that .Net Core is expecting ConsoleApplicationLibrary to be a NuGet package. If you want to reference a project, use "ConsoleApplicationLibrary": {"target": "project", "version": "1.0.0-*"}.
After you do that, don't forget to restore packages.
Ok, it's strange, but after disabling resharper, restarting VS and rebuilding solution, it works fine. It seems there is prolem with resharper support for .net core. (resharper v.9.1.3). From this: resharper ultimate blog i understand that only ultimate version supports .net core for now.
.NetCoreApp is a platform and .NetStandard.Library is a library supposed to be cross platform (portable class library) for various .NET platforms runtimes.
You can include a direct reference (package) of NetStandard.Library in any of your .NET platform project that is supported, for ex .NETCoreApp (Dot Net Core 1.X)
Reference: https://learn.microsoft.com/en-us/dotnet/articles/standard/library
I had the same issue and it turned out I needed to update Resharper to it's latest version. I had v9.1.1 so I updated it to 2016.3.2 and that fixed the issue.
Related
I have an asp.net form application using .net 4.6.1 running on windows
and a linux application using .netcore 1.1
I want to make a nuget that can be shared between both application.
I created a .net core library and it works pretty fine with my linux application
here is its project.jso
{
"version": "0.1",
"dependencies": {
"NETStandard.Library": "1.6.0",
"Newtonsoft.Json": "9.0.1",
"StackExchange.Redis": "1.2.0"
},
"frameworks": {
"netstandard1.4": {
"imports": "netcoreapp1.0"
}
}
}
I can add my nuget package to the windows application and build it with no error, but when I want to run the application I'm getting all erros like:
Could not load file or assembly 'System.Diagnostics.DiagnosticSource,
Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51
i'm using .net 4.6.1 so I believe it's .net core that is nagging
i can check in here and confirm that it's a .net core library.
I also setup the .net library in the production server. but still i'm getting the same error.
I tried all possible combination and version that i thought it would be logical. and have no clue how to solve it.
Im not sure why you say you are using net 4.6.1. Because you are using netstandard1.4 as framework, looking at your project.json file.
Try the following project.json file:
"buildOptions": {
"debugType": "portable",
"emitEntryPoint": true
},
"dependencies": {
"NETStandard.Library": "1.6.0",
"Newtonsoft.Json": "9.0.1",
"StackExchange.Redis": "1.2.0"
},
"frameworks": {
"netcoreapp1.1": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.1.0"
}
}
}
}
Make sure the production server has the runtime installed and Microsoft.NETCore.App-1.1.0
I am struggling to figure out how to force the npm (Nuget Package Manager) to resolve a specific version of the NetStandard1.X platform.
I am trying to use Serilog but the version of .NetStandard it supports is v1.3. Is there any way to force this behavior in the project.json file via some command or switch or option.
{
"version": "1.0.0-*",
"dependencies": {
"NETStandard.Library": "1.6.0",
"Serilog": "2.2.1"
},
"frameworks": {
"netstandard1.3": {
"imports": "dnxcore50",
"dependencies": {
}
}
}
}
When you specify v1.3, you end up with v1.6. Surely there must be a way of doing this? I am trying to upgrade an old .net framework 4.6 class library that was using log4net and I am struggling with the basics here.
Error Dump:
Package Serilog 2.2.1 is not compatible with netstandard1.6 (.NETStandard,Version=v1.6). Package Serilog 2.2.1 supports:
- net45 (.NETFramework,Version=v4.5)
- net46 (.NETFramework,Version=v4.6)
- netstandard1.0 (.NETStandard,Version=v1.0)
- netstandard1.3 (.NETStandard,Version=v1.3)
One or more packages are incompatible with .NETStandard,Version=v1.6.
DotNet Core Version Info:
Product Information:
Version: 1.0.0-preview2-003131
Commit SHA-1 hash: 635cf40e58
Your project.json restores on my machine correctly, so I would guess there is something wrong with packages/versioning.
Please try to change Serilog dependency version:
"Serilog": "2.3.0-dev-00711"
Or as you suggested yourself during our chat, move the decency into framework tag:
"frameworks": {
"netstandard1.6": {
"imports": "dotnet5.6",
"dependencies": {
"Serilog": "2.3.0-dev-00711"
}
}
}
I'm not quite sure I understand what the question is or what exactly is the problem you're having.
But one thing that jumps at me about your project.json is that the version of NETStandard.Library should be 1.6.0, even if you're targeting netstandard1.3. (Yes, it's confusing.)
(Question subtitle: Are resources not supported in .netstandard 1.3 or is my project file just messed up?)
I just created an example portable class library in Visual Studio 2015 Update 3 and added a sample resource file. Initially, the file project.json looks like this:
{
"supports": {
"net46.app": {},
"uwp.10.0.app": {},
"dnxcore50.app": {}
},
"dependencies": {
"Microsoft.NETCore": "5.0.0",
"Microsoft.NETCore.Portable.Compatibility": "1.0.0"
},
"frameworks": {
"dotnet": {
"imports": "portable-net452+win81"
}
}
}
Fine: No compile errors!
After that, I used the project properties to target .NETStandard 1.3.
Now project.json looks like this:
{
"supports": {},
"dependencies": {
"Microsoft.NETCore.Portable.Compatibility": "1.0.1",
"NETStandard.Library": "1.6.0"
},
"frameworks": {
"netstandard1.3": {}
}
}
Now I get the following build error - which means basically the the build action EmbeddedRessource is not supported:
I'm really no expert with project.json, but for me the things look inconsistent - and I have no idea, where the problem is.
in the first project.json: if I support net46, why is it importing net452?
in the second project.json: if I use netstandard1.3, why is there a dependency to the library in version 1.6?
and finally, what is .NETPortable, Version=v5.0? The renaming of .NET Core has taken place early this year - why are we still referencing version 5.0? Even MSDN doesn't know <TargetFrameworkVersion>5.0</TargetFrameworkVersion> which is specified in the csproj
For me, this seems like netstandard isn't only about the available libraries, tooling seems involved, too. But that does not explain, why it worked for dnxcore50.
You need Diagnostics.Tools and Resources.ResourceManager.
I got this working (for .NET Standard 1.4 though) by installing the pre versions, at this time:
"System.Diagnostics.Tools": "4.3.0-preview1-24530-04"
"System.Resources.ResourceManager": "4.3.0-preview1-24530-04"
I am having a hard time converting my asp.net (core) app from dnx46 to .netcoreapp1.0 because of two particular dependencies ( Microsoft.Azure.ServiceBus and System.IO.Ports.SerialPort )
Being positive, I'm making the bet that these feature will eventually land on .net core one day.. but in the meantime, I found that converting my app from moniker dnx46 to .netstandard1.3 allows me to resolve the ServiceBus dependency.
Resolving System.IO.Ports.SerialPort however is still an issue and I don't understand how to make this work. I was hoping that importing net462 framework in .netstandard1.3 moniker, would allow to find the System.IO.Ports.SerialPort object but it does not.
What am I missing ?
For reference, there's my project.json :
{
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.0.0-rc2-3002702",
"type": "platform"
},
"Microsoft.NETCore.Platforms": "1.0.1-*",
"Microsoft.EntityFrameworkCore": "1.0.0-rc2-final",
"Microsoft.EntityFrameworkCore.Sqlite": "1.0.0-rc2-final",
[...more stuff...]
},
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
// To be restored when they'll become available on .net core
// "Microsoft.WindowsAzure.ConfigurationManager": "3.2.1",
// "WindowsAzure.ServiceBus": "3.2.1",
}
},
"netstandard1.3": {
"buildOptions": {
"define": [ "INCLUDE_WINDOWSAZURE_FEATURE" ]
},
// Imports of net462 fixes loading of
// - NewtonSoft.Json
// - System.Runtime.Loader for "Microsoft.NETCore.App"
"imports": [
"net462"
],
"dependencies": {
"Microsoft.NETCore.Portable.Compatibility": "1.0.1-rc2-24027"
"Microsoft.WindowsAzure.ConfigurationManager": "3.2.1",
"WindowsAzure.ServiceBus": "3.2.1",
}
}
}
}
Resolving System.IO.Ports.SerialPort however is still an issue and I don't understand how to make this work. I was hoping that importing net462 framework in .netstandard1.3 moniker, would allow to find the System.IO.Ports.SerialPort object but it does not.
You can't reference System.IO.Ports.SerialPort when targeting .NET Core or .NET Standard, because this contract only exists in the full .NET Desktop framework.
This library might be eventually ported but in the meantime, you'll have to use .NET Desktop (e.g net462) instead of .NET Core.
Remove netcoreapp1.0 and netstandard1.3 and add net462 and it should work.
If you plan on deploying to a windows box and targeting net452, then simply take on a dependency on net452. I put together a migration guide to share my upgrading experiences, perhaps it might help? I initially had this misunderstanding that I would take a dependency of netstandard1.* and then "import": "net4*", David Fowler laughed at me and said something to the extent of "dude that's do wrong!". :P
You should change your project.json frameworks to look like this:
"frameworks": {
"net462": { }
}
I have been working on .NET Core from a few weeks now. At first it was a great overhaul from Microsoft to the old .NET way of doing things. But now its getting on my nerves. Below is my original global.json:
{
"projects": [ "src", "test" ],
"sdk": {
"version": "1.0.0-rc1-update1",
}
}
This is my project.json:
{
"version": "1.0.0-*",
"compilationOptions": {
"emitEntryPoint": true
},
"dependencies": {
"Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-final",
"Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final",
"Microsoft.AspNetCore.StaticFiles": "1.0.0-*",
"Microsoft.NETCore.Platforms": "1.0.1-*"
},
"commands": {
"web": "Microsoft.AspNet.Server.Kestrel"
},
"frameworks": {
"dnxcore50": { }
},
"exclude": [
"node_modules"
],
"publishExclude": [
"**.user",
"**.vspscc"
]
}
And here is my hosting.json:
{
"webroot": "wwwroot"
}
I have created an Empty ASP.NET Core 1.0 Web Application Project, all I am trying to do is create an AngularJs application. But I cannot access the wwwroot directory since I am not able to:
app.UseDefaultFiles();
app.UseStaticFiles();
I removed the dnx451 from my original project.json and also changed the global.json to:
{
"projects": [ "src", "test" ],
"sdk": {
"version": "1.0.0-rc1-update1",
"runtime": "coreclr",
"architecture": "x64"
}
}
Error:
Error NU1002 The dependency Microsoft.AspNetCore.StaticFiles 1.0.0-rc2-20248 in project QMS.UI does not support framework DNXCore,Version=v5.0. QMS.UI ..\QMS.UI\src\QMS.UI\project.json
I have read a lot of blogs and stackoverflow answers. Can anybody tell me in very high level way how does we:
Effectively find a valid package, that will suite our target framework.
Effectively make all frameworks (if listed in the project.json) happy with that dependency notation? (Sometimes I get an error, its available for dnx451 but not dnxcore50) (Should I use the #if dnxcore50... etc notations?)
Please help! I am going through a similar trouble in another project based on .NET Core.
The static file dependency is form RC2 and is not compatible with RC1 you use in rest of your project.
Either you use all packages from RC1 or all from RC2, but be aware that RC2 dependencies often break (one package requires version xyz, where other package is not yet updated and requires old library but due to API changes can't work with the newer version).
This are RC1 packages
"Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-final",
"Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final",
This are RC2 packages (you can recognize them on their name, Microsoft.AspNet.* packages got renamed to Microsoft.AspNetCore.* some time during RC2 cycle
"Microsoft.AspNetCore.StaticFiles": "1.0.0-*",
"Microsoft.NETCore.Platforms": "1.0.1-*"
Effectively find a valid package, that will suite our target framework.
First step is to target only the same versions. If you need a stable environment use RC1 until RC2 is released. However, be aware that there are quite a few breaking changes. Check out the ASP.NET Core GitHub annoucements (mostly breaking changes) for more information.
Effectively make all frameworks (if listed in the project.json) happy with that dependency notation? (Sometimes I get an error, its available for dnx451 but not dnxcore50) (Should I use the #if dnxcore50... etc notations?)
Depends on the assemblies you need. Some have compatible api with both target platforms, but most don't. Usually that's how you would switch out platform dependent assemblies/code.
Be aware that there is a difference if you use a Class Library (Package) or .NET Core application (Webproject, unit test project).
For RC1, the monikers are dnx451 (or dnx452, dnx46) for full .NET Framework targeting and dnxcore50 for .NET Core. For Class Libraries however, you have to use net451 (or net452/net46) for full .NET Framework target and dotnet5.x (x=1-4, i RC2 also 5) for .NET Core.