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"
}
}
},
Related
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.
I have a project that compiles that I want to test using xUnit. However although the project lets me add the references and builds, as soon as I add a using statement to the test class I get the red squiggly lines and the error "type or namespace could not be found."
Even though the xproj of the project I want to test has been added to references, and the namespaces do exist. It has to be something I have done, but I can't see what. Using earlier versions of .net, I have added references to test projects hundreds of times without an issue.
So what is different in the way .NET works, and why does it not recognize my namespaces in my referenced assemblies?
Update: I have removed xUnit and got MSTest working, but I have the same issue. So this may be a feature of the way I have dotnetcore set up, and the references in my json files more than anything else.
This structure works for me in .NET Core 1.0:
global.json
{
"projects": [ "src", "test" ],
"sdk": {
"version": "1.0.0-preview2-003121"
}
}
src/MyLibrary/project.json
{
"dependencies": { },
"frameworks": {
"netstandard1.3": {
"dependencies": {
"NETStandard.Library": "1.6.0"
}
}
},
"version": "1.0.0"
}
test/MyLibrary.Test/project.json
{
"dependencies": {
"dotnet-test-xunit": "2.2.0-preview2-build1029",
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0"
},
"MyLibrary": {
"target": "project",
"version": "1.0.0"
},
"xunit": "2.1.0"
},
"frameworks": {
"netcoreapp1.0": {
"imports": [
"dnxcore50",
"portable-net45+win8"
]
}
},
"testRunner": "xunit",
"version": "1.0.0"
}
Using this directory and project structure, both the Visual Studio Test Explorer and dotnet test work and can run xUnit tests.
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": {
}
}
}
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.
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-*"
}
}
}
}