Why are there multiple levels of dependecies in aspnet5 project.json? - .net-core

Why in the project.json is there a “dependencies” element outside of any of the target “frameworks”? When do dependencies go there versus under \frameworks\net451\frameworkAssemblies or \frameworks\dnxcore50\dependencies
"frameworks": {
"net451": {
"frameworkAssemblies": {
"System": "4.0.0.0",
}
},
"dnxcore50": {
**** "dependencies": {
"Microsoft.CSharp": "4.0.1-beta-23516",
"System.Collections": "4.0.11-beta-23516",
"System.Console": "4.0.0-beta-23516",
}
}
},
****"dependencies": {
"System.Diagnostics.Tools": "4.0.1-beta-23516",
"System.Threading.Timer": "4.0.1-beta-23516"
}

Each framework (net451/dnxcore50) can have different dependencies. Let's say that you are porting a legacy app that depends on some 3rd party NuGet library that's only available for desktop CLR. In that case you can add it to the dependencies in net451 and then mock it for dnxcore50. That way, you'll not get compilation errors.
frameworkAssemblies vs dependencies = GAC vs NuGet packages. frameworkAssemblies is only available for desktop CLR and it is used to reference GAC assmblies.

Related

Change Target Framework Version in ASP.NET Core app

Hi how can I change Target Framework Version in ASP.NET Core app in Visual Studio 2015 ?
I would like to target only "NETStandard.Library": "1.6.1".
My project.json frameworks section looks like:
"frameworks": {
"netcoreapp1.1": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.1.0"
}
}
}
}
and my xproj file target .NET 4.5.2
TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
It might be helpful for you to offer a little more color on what it is you're trying to do, but with what you've given here, some thoughts.
First, NETStandard.Library 1.6.1 is a library/package that is installed via NuGet, not a target framework you can run on. The closest framework you can target is "netstandard1.6", which would imply you're building a class library and not a console or other stand-alone application. To run that combination, your project.json should look like this (minimally):
{
"version": "1.0.0-*",
"dependencies": {
"NETStandard.Library": "1.6.1"
},
"frameworks": {
"netstandard1.6": {
"imports": "dnxcore50"
}
}
}
Based on what you've shown in your snippet though, it looks more like your intention was to create a console application, in which case, getting NETStandard.Library 1.6.1 would be done like this (framework section only):
"frameworks": {
"netcoreapp1.1": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.1.1"
},
"NETStandard.Library": "1.6.1"
}
}
}
Update for VS2017 is that you can edit your .csproj file and manually change <TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion> to <TargetFrameworkVersion>netstandard1.6</TargetFrameworkVersion>.
More information about specifying different target frameworks and switching between them can be found here.

DotNet Core RC2 Project and Net461 dependency resolve issue

Here is the project.json for the main dotnet core web project
"frameworks": {
"netcoreapp1.0": {
"imports": [
"dotnet5.6",
"dnxcore50",
"portable-net45+win8",
"net461"
]
}
}
If I add the following net461 class library project as a reference to above one. It won't build correctly.
"frameworks": {
"net461": {
}
}
and throw error like The dependency mscorlib could not be resolved.
However, if I create a project by using the old template(no project.json), and add it as a reference to dotnet core project. It works fine.
I wonder how to fix this?
What you're doing is creating a library that will run only on .Net Framework, and then trying to use it from an application that runs on .Net Core. That won't work.
If you want to run on .Net Core, then project.json of your application should contain:
"frameworks": {
"netcoreapp1.0": {
"imports": [
"dotnet5.6",
"dnxcore50",
"portable-net45+win8"
]
}
}
And library (the version of netstandard will depend on what you want to do):
"frameworks": {
"netstandard1.4": {
}
}
If you want to use dotnet CLI, but still run on .Net Framework, then have the following in both your library and application (where you include framework assemblies inside frameworkAssemblies):
"frameworks": {
"net461": {
"frameworkAssemblies": {
}
}
}

Add dll to MVC6 or use old web service

I need to reference a dll which calls an old web service (not svc, but the older one). I'm not quite sure how to go about doing that. I'm using the RC1 version. I could call the web service directly but I'm not sure how to do that either in MVC6.
If I add the dll directly I get the error:
The name '*' does not exist in the current context
FieldOps.DNX Core 5.0
Here's what part of my project.json looks like where the library added is called "MyLibrary":
"frameworks": {
"dnx451": {
"frameworkAssemblies": {
"System.Runtime.Serialization": "4.0.0.0",
"System.ServiceModel": "4.0.0.0"
},
"dependencies": { "MyLibrary": "2.2.0" }
},
"dnxcore50": {
"dependencies": {
"System.Runtime.Serialization.Primitives": "4.1.0-beta-23516",
"System.ServiceModel.Primitives": "4.1.0-beta-23516",
"System.ServiceModel.Http": "4.0.11-beta-23516",
"System.ServiceModel.NetTcp": "4.1.0-beta-23516",
"System.ServiceModel.Duplex": "4.0.1-beta-23516",
"System.ServiceModel.Security": "4.0.1-beta-23516",
"System.Net.NameResolution": "4.0.0-beta-23516",
"System.Net.Security": "4.0.0-beta-23516",
"System.Security.Principal.Windows": "4.0.0-beta-23516",
"System.Diagnostics.Tools": "4.0.1-beta-23516"
}
}
},

Asp.Net 5 class library DataAnnotation errors

I just added a class library project to my new solution and am only given the option of the new class library type. I created my domain classes, which use EF data annotations from System.Component.DataAnnotations. The classes themselves have no errors but the project wont build. I get these errors.
Severity Code Description Project File Line
Error CS0234 The type or namespace name 'DataAnnotations' does not exist in the namespace 'System.ComponentModel' (are you missing an assembly reference?) TraderToolkit2016.DomainClasses..NET Platform 5.4 C:\Users\Thomas Donino\Documents\GitHubVisualStudio\TraderToolkit2016\TraderToolkit2016.DomainClasses\AppClasses\DailyClose.cs
I have the assembly referenced. Why am I getting these errors?
Here is my project.json file, DataAnnotations added automatically from VS right click.
{
"version": "1.0.0-*",
"description": "TraderToolkit2016.DomainClasses Class Library",
"authors": [ "Thino" ],
"tags": [ "" ],
"projectUrl": "",
"licenseUrl": "",
"frameworks": {
"net451": {
"frameworkAssemblies": {
"System.ComponentModel.DataAnnotations": "4.0.0.0"
}
},
"dotnet5.4": {
"dependencies": {
"Microsoft.CSharp": "4.0.1-beta-23516",
"System.Collections": "4.0.11-beta-23516",
"System.Linq": "4.0.1-beta-23516",
"System.Runtime": "4.0.21-beta-23516",
"System.Threading": "4.0.11-beta-23516"
}
}
}
}
This mean that you are making your project compatible with 2 platforms. one is net451 and another is dotnet5.4.
"frameworks": {
"net451": {
"frameworkAssemblies": {
"System.ComponentModel.DataAnnotations": "4.0.0.0"
}
},
This means that you have added reference of System.ComponentModel.DataAnnotations only to net451 target. and that's why you get following error:
are you missing an assembly reference?) TraderToolkit2016.DomainClasses..NET Platform 5.4
Notice the 5.4 in the end of error message.
Now the solution is to either remove dotnet5.4 if you dont need it or add a reference of System.ComponentModel.DataAnnotations to dotnet5.4 to it as well. You can do that by simply installing this nuget package:
https://www.nuget.org/packages/System.ComponentModel.Annotations/4.0.11-beta-23516
Or simply modifying the file so that it looks like this:
"dotnet5.4": {
"dependencies": {
"Microsoft.CSharp": "4.0.1-beta-23516",
"System.Collections": "4.0.11-beta-23516",
"System.Linq": "4.0.1-beta-23516",
"System.Runtime": "4.0.21-beta-23516",
"System.Threading": "4.0.11-beta-23516"
"System.ComponentModel.Annotations": "4.0.11-beta-23516"
}
}

What is the difference between 'dependencies' and 'frameworkAssemblies' in project.json?

The documentation for using project.json for ASP.NET 5 applications includes a sample project.json file (abbreviated version below).
What is the difference between frameworkAssemblies and dependencies?
And why does dnx451 use one and dnxcore50 use the other?
{
"version": "0.1-alpha-*",
...
"frameworks": {
"dnx451": {
"frameworkAssemblies": {
...
}
},
"dnxcore50": {
"dependencies": {
...
}
}
}
frameworkAssemblies refers to assemblies present in GAC (global assembly cache).
Consider the following example:
I want to use ADO.NET apis(SqlConnection, SqlCommand) to work with a SQL Server database. I know that these apis are part of System.Data.dll and so want to reference it. Now when the full version of .NET Framework is installed, it installs some assemblies in the GAC (which has this System.Data.dll too) and hence you see a reference to frameworkassemblies in the below example. Coming to CoreClr, I need to find out in which package these types exist. For this you could use the website called PackageSearch(built by an ASP.NET team member) where you can search for a type and find the package name. Based on this you will find System.Data.SqlClient to be the package. Since this package is built for CoreClr, it is part of dependencies section within the dnxcore50 section.
{
"version": "1.0.0-*",
"description": "Test App",
"dependencies": {
},
"frameworks": {
"dnx451": {
"frameworkAssemblies": {
"System.Data": "4.0.0.0"
}
},
"dnxcore50": {
"dependencies": {
"System.Data.SqlClient": "4.0.0-beta-*"
}
}
}
}
Now let's say you want to even add support for json serialization and deserialization in your app and want to reference Json.Net nuget package. Json.Net nuget package supports both the desktop and core clr and hence you would put it in the dependencies section common to both frameworks.
{
"version": "1.0.0-*",
"description": "Test App",
"dependencies": {
"Newtonsoft.Json": "6.0.6"
},
"frameworks": {
"dnx451": {
"frameworkAssemblies": {
"System.Data": "4.0.0.0"
}
},
"dnxcore50": {
"dependencies": {
"System.Data.SqlClient": "4.0.0-beta-*"
}
}
}
}

Resources