Today, I was following multiple tutorial to run a C# application on Linux but always got stuck at the command dnu restore which was returning me a not found error. Later on, I found out this page which seems to indicate that the new command is dotnet restore and when I tried it, it worked.
Are the dnu and dnx commands completely replaced?
Also, is there some documentation somewhere about the dotnet commands?
Is the dotnet command replacing dnu and dnx commands?
Yes. They are introducing new command line toolchain, ASP.NET 5 will transition to the new tools for RC2. This is already in progress. There will be a smooth transition from DNX to these new .NET Core components.
Are the dnu and dnx commands completely replaced?
No. You can use dnu and dnx, if you follow this instruction Installing .NET Core on Linux.
Is there some documentation somewhere about the dotnet commands?
CLI Repo / Intro to .NET Core CLI - v1.0.0
Here the basic things
1 dnu restore & dnx run works for version 1.0.0-rc1-update2 coreclr x64 (check using dnvm list) and project.json file needs minimum
"compilationOptions": {
"emitEntryPoint": true
},
"frameworks":{
"dnxcore50":{
"dependencies": {
"System.Console":"4.0.0-*"
}
}
}
2 dotnet restore & dotnet run works for version 1.0.0-rc2-23811 and project.json file needs minimum
"compilationOptions": {
"emitEntryPoint": true
},
"dependencies": {
"NETStandard.Library": "1.0.0-rc2-23811"
},
"frameworks": {
"dnxcore50": { }
}
Along with this need NuGet.config file.
Now, based on How project.json file configured and dnvm active set, you need to use command.
Related
I feel like I'm missing something obvious, but searching google, this site and the .Net Core SLI issues section on GitHub did not immediately return an answer, nor did reading the documentation for the .Net Core project.json format.
In plain old C# projects (regular .Net, not Core) scaffolded by Visual Studio (not VSCode), usually running a build will put files in
%project root%/bin/Debug
out of the box, or
%project root%/bin/Release
if you choose publish.
In VSCode with .Net Core, by default build puts files in
%project root%/bin/Debug/netcoreapp1.0.
however if you run
dotnet publish
on the command line, it will put the files in a release folder inside
%project root%/bin/Debug/netcoreapp1.0.
resulting in a structure like
%project root%/bin/Debug/netcoreapp1.0/release.
If you have specified to build for a specific platform target in your project.json then it will similarly put the files in
%project root%/bin/Debug/netcoreapp1.0/PlatformName.
For example
%project root%/bin/Debug/netcoreapp1.0/win7-x64.
My question is, why does .Net Core put the release folder inside the debug folder and since I prefer the old directory structure, is there a way I can tell .Net Core to do it that way instead, say via some project.json property or cli flag similar to how say typescript allows you to specify an outDir?
Testing this with the default hello world project provided by 'dotnet new', my modified project.json looks like this:
{
"version": "1.0.0-*",
"buildOptions": {
"debugType": "portable",
"emitEntryPoint": true
},
"dependencies": {},
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
//"type": "platform",
"version": "1.0.0"
}
},
"imports": "dnxcore50"
}
},
"runtimes": {
"win7-x64": { }
}
}
According to the documentation (bold is mine):
dotnet publish [--framework] [--runtime] [--build-base-path] [--output] [--version-suffix] [--configuration] []
...
-c, --configuration [Debug|Release]
Configuration to use when publishing. The default value is Debug.
So you need to use:
dotnet publish -c Release
(there's also the --output parameter to specify the destination folder: the documentation also states the default, which matches what you are seeing)
According to Mapping the .NET Platform Standard to platforms .NET Platform Standard 1.5 have to be compatible with .NET Framework 4.6.2. I have tried to use it (make new .NET Platform Standard class library, then new .Net Framework 4.6.2 console application), but the library is not recognized. What I am doing wrong?
project.json in class library:
{
"version": "1.0.0-*",
"dependencies": {
"NETStandard.Library": "1.5.0-rc2-24027"
},
"frameworks": {
"netstandard1.5": {
"imports": "dnxcore50",
"buildOptions": { "embed": "true" }
}
}
}
If you get the latest .net core RTM release and the Update 3 VS tooling, things are a little nicer than they were during the RC period. Still don't have easy project references from csproj referencing xproj - but, you can get things to talk by packing up the xproj output into a nuget package, then using the package manager to install that package. Also, you shouldn't need the imports on the framework, nor the dependency on netstandard.library, at least I don't. Here's how I've done it:
Create a .cmd file which will package the nuget files and two copy the output files to the folder where the package manager is expecting them. Here's that script, I call it makeNuget.cmd:
IF "%1" == "%2" (
dotnet pack --no-build --configuration %1 -o ../%3
xcopy %4 "...\%3\lib\%5\" /Y
)
Add a postbuild script in the project.json of the xproj to run the script
"scripts": {
"postcompile": [
"makeNuget.cmd %compile:Configuration% Release packages\%project:Name% %compile:OutputDir% %compile:TargetFramework%"
]
}
This should leave you with a nuget package in the packages\[projectName]\ folder at the root of your solution, with the binaries in the packages\[projectName]\lib\[targetFramwork]\ folder
Now, you need to add the packages folder as a package source, so first open the package manager console, then click the little gear to add a package source (or Ctrl+Q, package sources, Enter). Then click the add button, name this source, browse or type in the packages directory and hit ok.
In the package manager console, make sure both your package source and project are selected in the drop downs at the top.
install-package [your package name]
AFAIK, that's as good as it gets at the moment.
Do you really need .Net Framework 4.6.2 app?
I just created PCL (Portable class library) targeting .NETStandard1.4 and I can use it in WPF app which is targeting .NET Framework 4.6.1.
Here is how my project.json looks like in PCL project:
{
"supports": {},
"dependencies": {
"Microsoft.NETCore.Portable.Compatibility": "1.0.1",
"NETStandard.Library": "1.6.0"
},
"frameworks": {
"netstandard1.4": {}
}
}
I recently set up a very basic .net web project and used dapper in my repository to access a database. It works and builds with no errors on my local computer, but when i attempt to build on VSTS, i get an error saying that certain packages are not compatible with .net framework v5.4 or v5.0 (tried a few different frameworks in an attempt to get it to build.)
Here's the project.json file in question that contains dapper. This builds and restores without any issues locally on my computer:
{
"version": "1.0.0-*",
"description": "ProjectPOC.Core.Implementations Class Library",
"authors": [ "CBergeron" ],
"tags": [ "" ],
"projectUrl": "",
"licenseUrl": "",
"dependencies": {
"ProjectPOC.Core.Infrastructure": "",
"ProjectPOC.Core.Models": "",
"Microsoft.Extensions.OptionsModel": "1.0.0-rc1-final",
"Dapper": "1.50.0-beta9"
},
"frameworks": {
"net451": {
"dependencies": {
}
},
"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"
}
}
}
}
When This project is built on the VSTS hosted build agent, i'm running the preinstall.ps1 script that's commonly being used here:
# bootstrap DNVM into this session.
"bootstrapping dnvminstall..."
&{$Branch='dev';iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.ps1'))}
"finished bootstrapping"
"Loading global.json"
# load up the global.json so we can find the DNX version
$globalJson = Get-Content -Path $PSScriptRoot\global.json -Raw -ErrorAction Ignore | ConvertFrom-Json -ErrorAction Ignore
"finished loading global.json"
if($globalJson)
{
$dnxVersion = $globalJson.sdk.version
"setting DNX version.. to $dnxVersion "
}
else
{
Write-Warning "Unable to locate global.json to determine using 'latest'"
$dnxVersion = "latest"
}
# install DNX
# only installs the default (x86, clr) runtime of the framework.
# If you need additional architectures or runtimes you should add additional calls
# ex: & $env:USERPROFILE\.dnx\bin\dnvm install $dnxVersion -r coreclr
"installing DNX"
& $env:USERPROFILE\.dnx\bin\dnvm install $dnxVersion -Persistent
#& $env:USERPROFILE\.dnx\bin\dnvm install $dnxVersion -r clr
#& $env:USERPROFILE\.dnx\bin\dnvm install $dnxVersion -r coreclr
#& $env:USERPROFILE\.dnx\bin\dnvm use $dnxVersion
& $env:USERPROFILE\.dnx\bin\dnvm list
"finished DNX install "
"DNU restoring....."
# run DNU restore on all project.json files in the src folder including 2>1 to redirect stderr to stdout for badly behaved tools
Get-ChildItem -Path $PSScriptRoot\src -Filter project.json -Recurse | ForEach-Object { & dnu restore $_.FullName 2>1 }
#dnu restore
"finsihed DNU restore"
This script is installing the following dnx based on the build logs, which matches my dnvm listing on my local machine:
2016-05-19T03:45:19.1014995Z installing DNX
2016-05-19T03:45:19.9042850Z Downloading dnx-clr-win-x86.1.0.0-rc1-update2 from https://www.nuget.org/api/v2
2016-05-19T03:45:22.7176602Z Installing to C:\Users\buildguest\.dnx\runtimes\dnx-clr-win-x86.1.0.0-rc1-update2
2016-05-19T03:45:22.7766619Z Adding C:\Users\buildguest\.dnx\runtimes\dnx-clr-win-x86.1.0.0-rc1-update2\bin to process PATH
2016-05-19T03:45:22.8456619Z Adding C:\Users\buildguest\.dnx\runtimes\dnx-clr-win-x86.1.0.0-rc1-update2\bin to user PATH
2016-05-19T03:45:22.8826599Z Native image generation (ngen) is skipped. Include -Ngen switch to turn on native image generation to improve application startup time.
2016-05-19T03:45:23.0276682Z Active Version Runtime Architecture OperatingSystem Alias
2016-05-19T03:45:23.0346603Z ------ ------- ------- ------------ --------------- -----
2016-05-19T03:45:23.0356615Z * 1.0.0-rc1-update2 clr x86 win
2016-05-19T03:45:23.0586614Z finished DNX install
2016-05-19T03:45:23.0596622Z DNU restoring.....
2016-05-19T03:45:23.2796607Z Microsoft .NET Development Utility Clr-x86-1.0.0-rc1-16609
2016-05-19T03:45:23.4785866Z GET https://api.nuget.org/v3/index.json
2016-05-19T03:45:23.5821917Z OK https://api.nuget.org/v3/index.json 123ms
2016-05-19T03:45:23.6261910Z GET https://www.myget.org/F/aspnetvnext/api/v2/
2016-05-19T03:45:24.4737562Z OK https://www.myget.org/F/aspnetvnext/api/v2/ 847ms
2016-05-19T03:45:24.4787560Z GET https://www.myget.org/F/aspnetmaster/
2016-05-19T03:45:25.1793928Z OK https://www.myget.org/F/aspnetmaster/ 700ms
After it finishes the restore from nuget, during the build it throws errors like this for the package library with dapper in it and anything that references it:
Unable to resolve dependency System.Collections.NonGeneric 4.0.1-rc2-24027
...
2016-05-19T03:47:01.3562201Z ##[error]Platform\POC\ProjectPOC.Web.API\src\ProjectPOC.Core.Implementations\project.json(0,0): Error NU1002: The dependency System.Collections.NonGeneric 4.0.1-rc2-24027 in project ProjectPOC.Core.Implementations does not support framework .NETPlatform,Version=v5.4.
2016-05-19T03:47:01.3602187Z 5>C:\a\1\s\Platform\POC\ProjectPOC.Web.API\src\ProjectPOC.Core.Implementations\project.json : error NU1002: The dependency System.Collections.NonGeneric 4.0.1-rc2-24027 in project ProjectPOC.Core.Implementations does not support framework .NETPlatform,Version=v5.4. [C:\a\1\s\Platform\POC\ProjectPOC.Web.API\src\ProjectPOC.Core.Implementations\ProjectPOC.Core.Implementations.xproj]
Again this is building, running, deploying to azure, etc flawlessly from my local machine in VS2015, so i feel like it has something to do with the hosted build agent and it's dnx/dnvm/nuget setup. Is there something that i need to add to the build agent or something i need to do to the dnvm/nuget install to get the correct versions of everything? I also uploaded my nuget.config to the build agent and that also didn't help. I can provide more of the logs on request.
my local dnvm list looks like this:
Active Version Runtime Architecture OperatingSystem Alias
------ ------- ------- ------------ --------------- -----
1.0.0-beta8 clr x64 win
1.0.0-beta8 coreclr x64 win
1.0.0-beta8 coreclr x86 win
1.0.0-rc1-update1 clr x64 win
1.0.0-rc1-update1 clr x86 win
1.0.0-rc1-update1 coreclr x64 win
1.0.0-rc1-update1 coreclr x86 win
* 1.0.0-rc1-update2 clr x86 win default
Thanks in advance if anyone can provide any help with this or has run into a similar issue before with the new .net stuff
I met this issue before and it did not work on my local machine. And I get it work by use the "1.50.0-beta8" version for Dapper instead of "1.50.0-beta9". beta8 use older dependencies then beta9.
This issue seems to be caused by the change here: Rename "dotnet" to "NETStandard" but I haven't got time to figure it out.
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.
Related: System.Environment in .NET Core
I'm trying to compile a program which uses Environment.Exit in .NET Core. I've used yo aspnet to create the default console application, installed System.Runtime.Extensions and then added a call to Environment.Exit(1) (full sample on github). When running dnu build I get this error:
C:\git\environmentexit\ConsoleApplication\Program.cs(13,25): DNXCore,Version=v5.0 error CS0117: 'Environment' does not contain a definition for 'Exit'
As far as I can tell, this corefx pull request should mean that Environment.Exit is exposed, so I can't figure out what else I'm missing.
Any ideas?
First of all I want to confirm that the problem exist in the current stable version of DNX: 1.0.0-rc1-update1 installed together with Visual Studio 2015 Update 1. The problem is already fixed in the current unstable build 1.0.0-rc2-16343.
I try to describe below very detailed how everybody can reproduce the problem step by step. In the next step I would show how to install the latest unstable build of DNX (it's 1.0.0-rc2-16343 today) and to compile your demo successfully. Finally I show how to uninstall unstable build of DNX go back to 1.0.0-rc1-update1.
First of all it's important to understand that one can install multiple version of DNX. On the other side all the packages resolved by usage "Restore Packages" in the context menu of the project or by usage of "dnu restore" command will be saved (cached) in the common folder %USERPROFILE%\.dnx\packages. The dependencies will be resolved from NuGet. To be exactly there are the file %APPDAT%\NuGet\NuGet.Config which contains the configuration of NuGet with URLs used for resolving of dependencies. Thus one can have wrong results after "playing" with different NuGet configurations and with different versions of DNX. I find such behavior as the large design problem of DNX today. I hope that it will be fixed soon.
In any way I strictly recommend to delete all files from %USERPROFILE%\.dnx\packages to have deterministic results. Additionally one should verify NuGet configuration to load the files only from the starndard NuGet source https://api.nuget.org/v3/index.json (or https://www.myget.org/F/aspnetvnext/api/v2/) and optionally from https://www.myget.org/F/aspnetvnext/api/v3/index.json (or https://www.myget.org/F/aspnetmaster/api/v2), which can contains additional ASP.NET stable packages. One can either edit the file %APPDAT%\NuGet\NuGet.Config manually or to check the described above sources in Visual Studio in menu: "Tools" / "NuGet Package Manager" / "Package Manager Settings" and choosing "Package Sources" finally.
1) I removed all files under %USERPROFILE%\.dnx\packages
2) verified using "dnvm list" that I have only 1.0.0-rc1-final and 1.0.0-rc1-update1 versions of DNX. I uninstalled some unneeded version using something like "dnvm uninstall 1.0.0-rc2-16343 -r coreclr -arch x86" and verified that the 1.0.0-rc1-update1 is default by usage "dnvm upgrade". After that the "dnvm list" displayed:
3) set only https://api.nuget.org/v3/index.json in my initial configuration:
After building of your demo with Program.cs
using System;
namespace ConsoleApplication
{
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine("Goodbye, cruel world");
Environment.Exit(1);
}
}
}
and project.json
{
"version": "1.0.0-*",
"description": "ConsoleApplication Console Application",
"authors": [
""
],
"tags": [
""
],
"projectUrl": "",
"licenseUrl": "",
"tooling": {
"defaultNamespace": "ConsoleApplication"
},
"commands": {
"ConsoleApplication": "ConsoleApplication"
},
"dependencies": { },
"frameworks": {
"dnx451": { },
"dnxcore50": {
"dependencies": {
"System.Console": "4.0.0-*",
"System.Runtime": "4.0.21-*",
"System.Runtime.Extensions": "4.0.11-*"
}
}
}
}
I get the following dependencies resolved
and the error message
Now I installed the latest unstable DNX using
dnvm upgrade -u -r coreclr -arch x64
dnvm upgrade -u -r clr -arch x64
dnvm upgrade -u -r coreclr
dnvm upgrade -u -r clr
The command "dnvm list" displayed
After that I modified the NuGet configuration to use https://www.myget.org/F/aspnetvnext/api/v3/index.json additionally:
Then I modified sdk.verison of global.json from "1.0.0-rc1-update1" to "1.0.0-rc2-16343" in the GUI of Visual Studio:
and saved the changes. After that I made "Restore Packages" and build the project once more. I get the following versions of dependencies:
and the program could be executed without any error.
It's vary important to mention that even if we would change the sdk.verison back to "1.0.0-rc1-update1" we will still have the same resolution of dependences from rc2-16343 because it will be used the packages cashed in %USERPROFILE%\.dnx\packages. It's really important to change NuGet configuration to original state (uncheck URL https://www.myget.org/F/aspnetvnext/api/v3/index.json) and delete all %USERPROFILE%\.dnx\packages. I would recommend you to deinstall unneded night build of DNX by usage of
dnvm upgrade
dnvm uninstall 1.0.0-rc2-16343 -r coreclr -arch x64
dnvm uninstall 1.0.0-rc2-16343 -r clr -arch x64
dnvm uninstall 1.0.0-rc2-16343 -r coreclr
dnvm uninstall 1.0.0-rc2-16343 -r clr
After all the steps one should have the same state in "dnvm list" as initially. One can verify that %USERPROFILE%\.dnx\runtimes don't contains any directories with 1.0.0-rc2-16343, the file %USERPROFILE%\.dnx\alias\default.txt contains dnx-clr-win-x86.1.0.0-rc1-update1 and the PATH contains only %USERPROFILE%\.dnx\runtimes\dnx-clr-win-x86.1.0.0-rc1-update1\bin and not references to 1.0.0-rc2-16343. In other words we finished our test and are returned back to stable rc1-update1.