I'm using Visual Studio 2015 CTP 6 on Windows 8.1.
I'm trying to write a Web API using ASP.NET v5, with its new project file format. I've added a reference to Noda Time v1.3.0 to my project.json
file, and the editor in Visual Studio picks it up, but the build process fails.
Repro recipe, right from scratch:
Open project.json
, and in the (badly formatted) "dependencies" section, add an extra line at the start (to avoid having to add a comma to another line):
"NodaTime": "1.3.0",
Controllers\ValuesController.cs
Edit the parameterless Get()
method so that the body is:
return DateTimeZoneProviders.Tzdb.Ids;
DateTimeZoneProviders
will have red squiggles, which is reasonable - we don't have a using
directive yet.DateTimeZoneProviders
and hit Ctrl+. - you should be offered "using NodaTime;
" as a potential fix... so Intellisense (and thus Roslyn) definitely knows about the dependency.In Explorer, if you look in the BugDemo
solution directory, you'll find an artifacts\obj\BugDemo\Debug\ProjectRawReferences
directory containing "ASP.NET Core 5.0" and "ASP.NET 5.0" directories, both of which have a lot of DLLs in... but not Noda Time.
Right-clicking on the project and selecting "Restore packages" doesn't fix this.
When I build the same project using Project K, a kpm restore
does pick up Noda Time, and if you add a section to project.json
as below, then k web
works and visiting http://localhost:5001/api/values will show you all the TZDB time zone IDs:
"commands": { "web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener --server.urls http://localhost:5001" },
So, what am I doing wrong? Or is it just a bug?
Dependency Injection (often called just DI) is a software design pattern that helps us create loosely coupled applications. It is an implementation of the Inversion of Control (IoC) principle, and Dependency Inversion Principle (D in SOLID).
. NET 6.0 has more advantages than working with the . NET 5.0 as . NET 6.0 has more improvement on the performance which also includes some major advantage as it has intelligent code editing and also it is called the fastest full-stack web framework.
When you build, check out the "Project" column - it notes that the build that is failing is "ASP.NET Core 5.0" (not "ASP.NET 5.0"). In the upper left dropdown of the code editor, you can choose different views - if you select the "ASP.NET Core 5.0" one, you'll see that the NodaTime namespace is undefined.
It looks like the new ASP.NET project templates are creating multi-targeted apps, both aspnet50 and aspnetcore50.
ASP.NET 5.0 is (currently) based on .NET 4.5.x, so the NodaTime portable (net4) satisfies that platform. ASP.NET Core 5.0 is based on the new CoreClr (aspnetcore50), and there's no binaries in the NodaTime library that support it.
To resolve, you can just drop support for CoreClr in your application by removing the "aspnetcore50" entry in project.json under "frameworks":
"frameworks": { "aspnet50": { } //"aspnetcore50": { } },
Now your app should build just targeting ASP.NET 5.0 and not the CoreClr.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With