I am trying to use Process.Start in an ASP.NET Beta8 project that I would like to be able to run on Linux using .Net core. Visual studio is giving me an error at compile time:
Error CS0103 The name 'Process' does not exist in the current context
Going back and hovering my mouse over Process.Start I can see a message that says "DNX core 5.0 not available". Is there a different way of invoking processes in asp.net 5? Or perhaps this isn't possible yet?
Here is exactly how I am using it:
var p = Process.Start("someprog", "someargs");
p.WaitForExit();
So it was me not really not knowing how the new project system works for .net. I needed to add a dependency to my project.json:
"frameworks": {
"dnx451": { },
"dnxcore50": {
"dependencies": {
"System.Diagnostics.Process": "4.1.0-beta-23409"
}
}
},
Adding this made it compile. Although I am not sure if that version number is correct.
Related
I'm wonderinf if it possible to deploy my asp.net core application if I also use some library from .NET 4.5.2.
To describe my problem, in my app I use SyndicationFeed which comes from full .NET
and in my project.json in "framework" section I have:
"frameworks": {
"net452": {
"frameworkAssemblies": {
"System.ServiceModel": ""
},
"dependencies": {
}
},
"netcoreapp1.1": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.1.0"
}
},
"imports": [
"dotnet5.6",
"portable-net45+win8"
]
}
}
In the other sections I use ASP.CORE packages like:
"Microsoft.EntityFrameworkCore.Design": "1.1.0",
"Microsoft.EntityFrameworkCore.Tools": "1.1.0-preview4-final",
"Hangfire.AspNetCore": "1.6.8",
and more.
So the question is is it possible to deploy to the IIS. Should I deploy to server with run with ASP.CORE or full .NET.
In short: yes, it's possible. But full .NET Framework required (on server).
Long story:
Having two frameworks in projects.json effectively creates two different apps (one for net462, other for netcoreapp1.1) during compilation/publishing. This is two different applications, compiled for different frameworks from same source code.
To run first (for net462) you need machine with .NET Framework installed. For other (for netcoreapp) you need .NET Core installed. You can't "swap" (run net462-build app on .NET Core and vice versa).
But looking at your project.json I can't believe your app compiles successfully. You need System.ServiceModel for your app to work. But it's available only for net462. This means that during compilation first app (for net462) compiles successfully, while second (net netcoreapp) should fail (class not found, namespace not found, etc).
Run dotnet build or dotnet publish from command line in project/solution folder. See any errors?
So, you can't create/build/run under .NET Core while you need packages/classes not available for .NET Core.
Possible solutions:
Replace package for netcore-compatible (if any exist, I don't know), or re-build (port) existing to be compatible (as Joel says);
Completely remove this package (implement required code yourself);
Do not target netcoreapp1.1;
Add conditional compilation (#if) where you use this package, so you will use if only in net462-version of your app. Otherwise (#else) add NotImplementedException, null result or something other (it depends) - effectively you will have two different apps after compilation: full-functional for net462 and restricted-functional for netcoreapp.
I was built my project(Class Library) in .Net core and trying to analyze my code using FxCop in VS2015.
But i am getting following error:
"could not identify platform for project"
Also i tried to set platform for my project. But i can't able to set it.
Any thing i missed here?
thanks,
Suresh
By referring this link Use code analysis with Visual Studio DNX project (.xproj)
I have added following lines in project.Json file now its working.
"frameworks": {
"net46": {
"buildOptions": {
"define": [ "CODE_ANALYSIS" ]
}
},
"netstandard1.6": {
"imports": "dnxcore50"
}
}
Note: After added the code in project.json file, close all visual studio application and start it. Then it will work.
I inherited a project and the tests ran fine. Today, I created a new class, and xunit errors out when I try to use this class in a test.
Both the test project and the app are targeting .NET Framework 4.6.1.
I do clean and rebuild on the both the solution and the test project, but I still get the error.
error:
Could not load type 'MyNewClass' from assembly 'MyApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
project.json:
"buildOptions": {
"warningsAsErrors": true
},
"testRunner": "xunit",
"dependencies": {
"xunit": "2.2.0-beta4-build3404",
"dotnet-test-xunit": "2.2.0-preview2-build1029",
"MyApp": "1.0.0-*",
"Microsoft.EntityFrameworkCore.InMemory": "1.0.0",
"NSubstitute": "1.9.2"
},
"frameworks": {
"net461": {
}
}
Anyone have any ideas how to fix this?
Sometimes for whatever reason .NET Core dependencies restore won't work as expected. I've just tried your project.json on my machine and it was complaining about xunit version, however after several project.json edits it was able to restore all the dependencies, and run tests successfully.
In such situations following might help:
Try dotnet restore and/or dotnet build commands in the folder where your project.json file is.
Delete project.json.lock file and try step #1.
Use dotnet test to run unit tests.
I find these commands to run .NET Core projects more stable and provide better error output for troubleshooting than Visual Studio.
So, my problem was that MyApp.dll was not getting updated/re-created, even after I did a clean and rebuild. I had to physically delete the files (including MyApp.dll) in MyApp\test\MyApp.Tests\bin\Debug\net461\win7-x86
I had this problem too and could solve it recreating the project.
Sometimes, things simply stops working correctly, as pointed in the others answers, and the best is just start over, restart the program, recreate the project, reboot the machine...
This is Visual Studio, sigh... :)
While dotnet cli is not yet ready to work with Visual Studio and dnu/dnx gives me huge amount of extra unneeded libraries I want to do the following.
I want to launch ASP.NET Core 1 project either using command line or console app using traditional .csproj approach.
I created a ASP.NET 4 project, included all dependencies and was able to compile it.
1st Attempt.
At first I tried to compile it into console app and launch through standard entry point:
// Entry point for the application.
public static void Main(string[] args) {
WebApplication.Run<Startup>(args);
}
It says: "No service for type 'Microsoft.Extensions.PlatformAbstractions.IApplicationEnvironment' has been registered."
Which means that dnx.exe creates additional dependency injection rules probably through PlatformServices.Create.
Does somebody know how to do it properly?
2nd Attempt
I compiled it into dll and tried to launch it through dnx.exe which gave me the error "Error: Unable to load application or execute command 'Microsoft.AspNet.Hosting'. Available commands: web.".
Here's my project.json:
{
"version": "1.0.0-*",
"compilationOptions": {
"emitEntryPoint": true
},
"webroot": "wwwroot",
"commands": {
"web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.Kestrel --server.urls http://*:5004"
},
"frameworks": {
"dnx451": {}
},
"entryPoint": "ManagementConsoleWeb",
"loadable": false
}
So what's the proper way? Is is possible at all?
Here're some thoughts.
ASP.NET Core 1 requires DNX bootstrap to work. Yes, it works under .NET 4.5.2 but DNX is a must. So basically it's strange you can reference ASP.NET Core 1 libraries in .csproj net451.
DNX bootstrap libraries are not available under Nuget for net451 moniker. So you can't reference them from .csproj
That means you can't DEBUG ASP.NET Core 1 using traditional .csproj class library or executable approach. Of course you can always connect to a running app but that's not convenient.
So our team now is working with DNX bootstrap for NET CORE 1 but we deliver outputs from .csproj build until RC2 release.
ASP.NET Core 1.0 uses IHostingEnvironment hostingEnvironment instead of IApplicationEnvironment applicationEnvironment.
Go through the ASP.NET Core Migration document for full detail.
I have installed Visual Studio 2015 Preview and created an ASP.Net 5 Empty Project.
I 'll use PostgreSQL in my application, so I added "Npgsql" NuGet Package in my project.
I added "using Npgsql" and tried to write a simple SQL connection test method but I get the error below :
Error CS0246 The type or namespace name 'Npgsql' could not be found
(are you missing a using directive or an assembly
reference?) WebApplication3.ASP.NET Core 5.0 AccountsController.cs
My project.json file :
"dependencies"
: {
"Microsoft.AspNet.Server.IIS": "1.0.0-beta1",
"EnterpriseLibrary.Data": "6.0.1304.0",
"Npgsql": "2.2.3.0",
"Microsoft.AspNet.Mvc": "6.0.0-beta1",
"Microsoft.AspNet.Diagnostics": "1.0.0-beta1",
"System.Data.Common": "1.0.0-beta1"
},
"frameworks": {
"aspnet50": {},
"aspnetcore50": { }
}
Is there any mistake or is it not possible to connect Postgres using asp.net-vnext right now ?
Besides, we want to develope code on Visual Studio and run on Ubuntu and we will have to use some third parties. Is it right time to go on with asp.net-vNext or choose some other open source language?
It feels like asp.net-vnext needs time to use in a project like that..
Just move whole "dependency" block under "aspnet50". Here is complete example of using PostgreSQL from ASP.NET 5
Have you tried to remove the line "aspnetcore50": { } ?
I'm not sure you'll be able to run it in Ubuntu just yet. Not sure that "EnterpriseLibrary.Data": "6.0.1304.0", is compatible with aspnetcore50.
Also if you use Entity Framework, keep in mind that EF7 still has a lot of features to be implemented.
I also wanted to create an application to be used both in Win and Lin but decided to go with windows only for now an leave it open enough so will be easy to change it later to support both OS. Do let you be mistaken with the false advertize of multiplatform (it's just marketing), this is not fully supported for big enterprise applications, not yet. I truly believe it will be soon, well I hope, I had the chance to go with Python tech but kept with .NET, I hope I haven't made a huge mistake.
Good luck.