How can I resolve a dependency in a vNext ASP.NET 5 project? When I try add a dependency in the project.json it cannot find System.Data.
I'm trying to close an NHibernate 4 ISession with Session.Close().
try
{
_transaction.Rollback();
}
finally
{
Session.Close(); // Compiler error
}
The type 'IDbConnection' is defined in an assembly that is not
referenced. You must add a reference to assembly 'System.Data,
Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
I got it to compile by adding the dependency, which doesn't exist in ASP.NET 5.0, to the project.json.
"frameworks": {
"aspnet50": {
"frameworkAssemblies": {
// Stuff in the global assembly cache(.net assemblies etc.)
"System.Data" : "4.0.0.0"
}
}
}
(I assume it works, my project isn't ready to test it out).
For more info on the new project and adding references and dependencies see the overview on ASP.NET 5.0.
Related
I hoping someone can help shed some light on how to get around this issue. I've noticed this issue while attempting to add a classic .csproj class library to a ASP.NET 5 RC1 xproj project and while attempting to add references to regualar .NET 4.5-4.6 assemblies to xproj based ASP.NET 5 RC1 projects. In this particular case I'm trying to add a reference to Microsoft.WindowsAzure.ServiceRuntime to an ASP.NET 5 WebApi project. I can see a wrap file get's generated that looks like this:
{
"version": "1.0.0-*",
"frameworks": {
"dnx46": {
"bin": {
"assembly": "../../lib/dnx46/Microsoft.WindowsAzure.ServiceRuntime.dll"
}
}
}
}
The reference in the project.json file looks like this:
"frameworks": {
"dnx46": {
"dependencies": {
"Microsoft.WindowsAzure.ServiceRuntime": "1.0.0-*"
}
}
},
When open up the project.lock.json file I see the following get added:
"DNX,Version=v4.6": [
"Microsoft.WindowsAzure.ServiceRuntime >= 1.0.0-*"
]
When I look at the references in visual studio I see the following:
What am I doing wrong? Is there any kind of workaround for this issue?
I am trying to develop my first ASP.Net web application and in my solution I have two projects. A Web Application and Class Library (Package) and noticed that the Web App has this for it's framework inside the project.json
"frameworks": {
"dnxcore50": { }
}
My understanding is that code makes my Web App target Net 5.0 Core but if I look at the project.json for the Class Library I see this:
"frameworks": {
"net451": { },
"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"
}
}
}
I have never heard of dotnet5.4 and what I read from google just confuses me. I think the net451 is the equivalent to dnx451 but I am not 100% on that.
What do I need to change in my project.json to get it to target the new .Net 5.0 core?
This is the result of the upcoming .NET Standard Platform. You can see the changes regarding this specific to rc1 here, the main part being;
Only class libraries should change to target net4x and dotnet5.x. For
class libraries the recommended conversion steps are:
In project.json:
Change dnx4x to net4x (e.g. dnx451 to net451)
Change dnxcore50 to
dotnet5.4
And in your CS files:
Change #if DNX451 to #if NET451
Change #if DNXCORE50 to #if DOTNET5_4
My solution have 3 projects :
Web (i added the connection string in the appsetting file)
Business (contains models class)
Infrastructure (contains DbContext)
I tried to make a migration :
dnx ef migration add firstMigration -s Web
I had this error :
System.InvalidOperationException: The current runtime target framework is not compatible with 'Infrastructure'.
Current runtime target framework: 'DNX,Version=v4.5.1 (dnx451)'
Version: 1.0.0-rc1-16202
Type: Clr
Architecture: x86
OS Name: Windows
OS Version: 10.0
Runtime Id: win10-x86
Please make sure the runtime matches a framework specified in project.json
When i put dnvm list, i have 1.0.0-rc1-final like a default runtime and i don't find 1.0.0*rc1-16202 in the list ?
The projet.json file of Infrastuture project is :
"frameworks": {
"dotnet5.4": {
},
"net451": {
"EntityFramework.Commands": "7.0.0-rc1-final",
"frameworkAssemblies": { "System.Runtime": "4.0.10.0" }
}
}
I had the same problem and I solved it by changing "net451" to "dnx451" in the project.json file under the "frameworks" object.
It's ok now, it was my mistake : i executed the command (dnx ef migrations add) in Infrasturtucre folder instead of web folder.
Step 1: Open VS 2015 RC and create a new "ASP.Net Web Application"
Step 2: Right-click the solution, add a new windows "Class Library" (a normal one, not the "Class Library (Package)"
Step 3: Put a method in Class1.cs in the class library. Doesn't matter what.
Step 4: Right-click "References" in the Web Project and add a reference to your class library.
Step 5: From a code file in the web project, call the method you made in Class1.cs
So for me, Class1.cs looks like this:
public class Class1
{
public void X()
{
}
}
And I added code in the web application like this:
var x = new ClassLibrary1.Class1();
x.X();
Step 6: Try to compile, you will get this error:
Error CS0246 The type or namespace name 'ClassLibrary1' could not be found (are you missing a using directive or an assembly reference?)
What magic must be done to make normal class libraries (of which I have a lot) work with ASP.Net 5 apps?
When downloading your project and building, I got the following error in the output:
C:\REDACTED\AspNet5Test\src\AspNet5Test\Startup.cs(26,25,26,38): DNX Core 5.0 error CS0246: The type or namespace name 'ClassLibrary1' could not be found (are you missing a using directive or an assembly reference?)
Note, especially the DNX Core 5.0 portion - .Net 4.5 libraries (such as your ClassLibrary1) are not compatible with .Net Core.
The easiest solution is to remove the dependency on dnxcore50 from your project.json file.
Current:
"frameworks": {
"dnx451": {
"dependencies": {
"ClassLibrary1": "1.0.0-*"
}
},
"dnxcore50": { }
},
Change to:
"frameworks": {
"dnx451": {
"dependencies": {
"ClassLibrary1": "1.0.0-*"
}
}
},
Does anybody know how to add project reference in ASP.NET vNext?
project.json
{
"dependencies": {
"myProject": ""
},
"configurations" : {
"net45" : { },
"k10" : { }
}
}
It doesn't work :(
I've found the solution.
You can use only ASP.NET vNext projects (I tried to use "Class library", but it works only with "ASP.NET vNext Classs Library"
You should use global.json to declare your folders.
when you save the project.json file,the References node in Solution Explorer shows the class library project and identifies it as a project in the properties window (other references such as Helios show up as NuGet package references).
if can not,you can try restart the vs