3

I have gone through some websites and found that .NET Core is using .NET CLI (.NET Command Line Interface). I have create a console application using .NET CLI and it is working fine

But when I am creating an ASP.NET Core web application using Yeoman and running the command “dotnet restore” then I am getting the following error:

Microsoft.CodeAnalysis.CSharp 1.1.0-rc1-20151109-01 is not compatible with DNXCore,Version=v5.0.

I also tried

dotnet restore -s https://api.nuget.org/v3/index.json

But getting the same error.

If I run “dnu restore” then it is working fine so my question is can I use .NET CLI for web application too or it is only limited to console application?

I have gone through the links

https://github.com/dotnet/cli & http://dotnet.github.io/getting-started/

but did not find any details that it supports ASP.NET Core web app or not?

3
  • Did you created your project via dotnet-cli too (via dotnet new command? Seems like your dependencries in project.json still refer to rc1. dotnet-cli only works for rc2 nightly builds (no official rc2 build yet) Commented Feb 20, 2016 at 19:14
  • when I am using "dotnet new" then it is creating a C# console application. I did not find any command to create ASP.NET Core web app using CLI so for scaffolding I am using yeoman and and then using CLI to restore and build. Commented Feb 20, 2016 at 19:25
  • But you can compare the project.json files and compare the dependencies that differ. dotnet-cli is still in early stage and ASP.NET Core 1.0 in the process of fully migrating to it (hence the delay in ASP.NET Core 1.0 RC2 release, that was supposed to come January). On the official nuget 3 feed there are only the official releases (RC1). It may be that you require newer versions of the dependencies. There is a myget feed at dotnet.myget.org/gallery/cli-deps that contains a more current version of Microsoft.CodeAnalysis.CSharp and the new Microsoft.AspNetCore.Mvc.* packages Commented Feb 20, 2016 at 19:43

3 Answers 3

6

I've spent a good hour on toying around with it and I got the "Welcome page" running with it.

As I suspected, you tried to use dotnet-cli with your dnx styled project and you you used the wrong nuget feed (the official one, rather than the nightly myget feeds).

For this demo project, just create a new folder and run dotnet new. This creates three files: NuGet.Config, project.json and Program.cs. You can delete the later one and just create a Startup.cs from below.

Startup.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;

namespace AspNetCoreCliDemo
{
    public class Startup
    {
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app)
        {
            app.UseIISPlatformHandler();
            app.UseWelcomePage();
        }

        // This doesn't work right now, as it can't resolve WebApplication type
        //public static void Main(string[] args) => WebApplication.Run<Startup>(args);

        // Entry point for the application.
        public static void Main(string[] args)
        {
            var host = new WebHostBuilder()
                        .UseDefaultConfiguration(args)
                        .UseServer("Microsoft.AspNetCore.Server.Kestrel")
                        .UseIISPlatformHandlerUrl()
                        .UseStartup<Startup>()
                        .Build();

            host.Run();
        }
    }
}

project.json:

{
  "version": "1.0.0-*",
  "compilationOptions": {
    "emitEntryPoint": true
  },

  "dependencies": {
    "NETStandard.Library": "1.0.0-rc2-*",
    "Microsoft.AspNetCore.Diagnostics": "1.0.0-rc2-*",
    "Microsoft.AspNetCore.IISPlatformHandler": "1.0.0-rc2-*",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-rc2-*"
  },

  "frameworks": {
    "dnxcore50": { }
  },

  "exclude": [
    "wwwroot",
    "node_modules"
  ],
  "publishExclude": [
    "**.user",
    "**.vspscc"
  ]
}

Note: Only dnxcore moniker is supported as of now.

Last but not least, the NuGet.Config that worked in my case:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <!--To inherit the global NuGet package sources remove the <clear/> line below -->
    <clear />
    <add key="cli-deps" value="https://dotnet.myget.org/F/cli-deps/api/v3/index.json" />
    <add key="dotnet-core" value="https://dotnet.myget.org/F/dotnet-core/api/v3/index.json" />
    <add key="api.nuget.org" value="https://api.nuget.org/v3/index.json" />
  </packageSources>
</configuration>

I didn't had the success with the two default feeds (api.nuget.org and dotnet-core) as it couldn't resolve a few dependencies. After adding the "cli-deps" feed, all packages were resolved and dotnet run worked. It will listen on the "http://localhost:5000" port and serve the welcome page.

You may get an error message about having more than one entry point, that's because you got a Main method in both Program.cs and Startup.cs. Just delete the Program.cs.

This should serve as an entry point.

dotnet-cli as of now doesn't support commands yet (ones formerly defined in the project.json file).

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks for your answer.. but It contains a lot of complexity and work around. If it has so many complexity then why should I opt for CLI. I am uisng yeoman for scaffolding and dnu and dnx commands. So what is the scaffolding tool or command for creating ASP.NET Core Web app wit CLI.
@Banketeshvar Narayan You're kind of jumping the gun on ASP.NET using CLI. This is a very big change in direction that is still under massive development and there is no roadmap. Scaffolding tools do not yet exist for ASP.NET Core using CLI...RC2 is only available via nightly builds and is not ready for beta/public consumption.
Thanks @Phasiq for your informative comment. my intention is not to blame any tool but to clarify my doubt. I think It would be better to wait for official release of RC2.
@Phasiq: It's not less than jumping on the RC1 wagon. You'll have to do plenty of changes, when RC2 comes no matter if you start with RC2 or RC1. In RC2 nightlies you just have to expect that the package restore fails more often when you add new dependencies or change stuff, especially if you use wildcards in version numbers. Though technically you could fix the version numbers and stay on that version for development. Neither of both is ready for production and if its a big project it may takes months until its finished, by then ASP.NET Core 1.0 should be released... I hope :P
@Tseng, I was addressing OP's question specifically about scaffolding that this kind of assistance is not yet available in the CLI version. For users who want a little more assistance starting out, that help doesn't currently exist for RC2. You can't just 'dotnet new' and get a working MVC project with CLI just yet nor are there any Yeoman scaffolding packages yet available. Meanwhile, RC1 certainly already has this capability as you can simply File > New Project right from Visual Studio.
3

Short Answer

For ASP.NET Core rc1, we use dnx and dnu.

For ASP.NET Core rc2, we use dotnet.

Longer Answer

I have gone through some websites and found that .NET Core is using .NET CLI (.NET Command Line Interface). I have create a console application using .NET CLI and it is working fine.

ASP.NET Core rc2 is also a console application. That is, it is a console application that starts the ASP.NET hosting layer.

But when I am creating an ASP.NET Core web application using Yeoman and running the command “dotnet restore” then I am getting the following error...

My sense is that you are running these commands:

yo aspnet
? What type of application do you want to create? Web Application
? What's the name of your ASP.NET application? MyApp

This creates an ASP.NET Core rc1 project. You can see this by looking at the resultant project.json file dependencies. They all say rc1-final. Result: you cannot build these with the dotnet command line. You still have to use the dnu build and the dnx <command> formulas.

...can I use .NET CLI for web application[s] too or it is only limited to console application?

In ASP.NET Core rc1, the dnx.exe made a call to new WebHostBuilder(), so we need to use dnx to start our web application. In ASP.NET Core rc2, the console application that contains our web app makes its own call to new WebHostBuilder(), so we can use the dotnet command line interface to start the app. So...

  • No you cannot use the dotnet CLI for ASP.NET Core rc1 Web Applications, because dnx.exe loads the ASP.NET Hosting Layer.
  • Yes you can use it for ASP.NET Core rc2 Web Applications, because your console application loads the ASP.NET Hosting Layer itself.

1 Comment

@BanketeshvarNarayan Your question was, "can I use .NET CLI for web application too or it is only limited to console application?" What I would do, in this situation, is to accept an answer to your original question, and then to ask another question about your new requirements.
0

Now I don't know what your exact error is, but this might be helpful:

Basically, you need to add the appropriate imports to your project.json:

    "frameworks": {
        "dnxcore50": { 
            "imports": "portable-net451+win8"
        }
    }

(As posted here: https://github.com/aspnet/Home/issues/1265)

These were my errors:

Errors in /webserver/project.json
    Package Microsoft.CodeAnalysis.CSharp 1.1.0-rc1-20151109-01 is not compatible with dnxcore50 (DNXCore,Version=v5.0). Package Microsoft.CodeAnalysis.CSharp 1.1.0-rc1-20151109-01 supports:
      - net45 (.NETFramework,Version=v4.5)
      - portable-net45+win8 (.NETPortable,Version=v0.0,Profile=Profile7)
    Package Microsoft.CodeAnalysis.Common 1.1.0-rc1-20151109-01 is not compatible with dnxcore50 (DNXCore,Version=v5.0). Package Microsoft.CodeAnalysis.Common 1.1.0-rc1-20151109-01 supports:
      - net45 (.NETFramework,Version=v4.5)
      - portable-net45+win8 (.NETPortable,Version=v0.0,Profile=Profile7)
    One or more packages are incompatible with DNXCore,Version=v5.0.

I generated the .Net Web App using the Swagger Code generator from http://editor.swagger.io/#/

After adding the imports, dotnet restore worked without problems.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.