freinn
freinn

Reputation: 1079

what is the general way to find what dependencies do I need on .net core?

I'm trying to create a simple .net core app from code I've found on some blogs. I'm on Ubuntu 16.04. My files are:

project.json

{
  "version": "1.0.0-*",
  "buildOptions": {
    "debugType": "portable",
    "emitEntryPoint": true,
    "preserveCompilationContext": true
  },
  "dependencies": {
    "Microsoft.Extensions.Configuration.Json": "1.0.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
    "Microsoft.AspNetCore.Server.WebListener": "0.1.0",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
    "Microsoft.Extensions.Logging.Console": "1.0.0",
    "Microsoft.Extensions.Configuration.FileExtensions": "1.0.0",
    "Microsoft.Extensions.Configuration.CommandLine": "1.0.0",
    "Microsoft.AspNetCore.StaticFiles": "1.0.0"
  },
  "frameworks": {
    "netcoreapp1.0": {
      "dependencies": {
        "Microsoft.NETCore.App": {
          "type": "platform",
          "version": "1.0.1"
        }
      },
      "imports": "dnxcore50"
    }
  }
}

Program.cs

using Microsoft.Extensions.Configuration; // for using IConfiguration
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Server.Kestrel;
using System.IO; // for using Directory

namespace ConsoleApplication
{
  public class Program
  {
    public static void Main(string[] args)
    {
      var config = new ConfigurationBuilder()
          .SetBasePath(Directory.GetCurrentDirectory())
          .AddJsonFile("hosting.json", optional: true)
          .Build();

      var host = new WebHostBuilder()
          .UseKestrel()
          .UseConfiguration(config)
          .UseContentRoot(Directory.GetCurrentDirectory())
          .UseIISIntegration()
          .UseStartup<Startup>()
          .Build();

      host.Run();
    }
  }
}

hosting.json

{
  "server.urls": "http://localhost:60000;http://localhost:60001"
}

The error I get when performing a dotnet publish is:

error CS0246: The type or namespace name 'Startup' could not be found (are you missing a using directive or an assembly reference?)

Also, remember please that I'm looking for a general way of knowing what dependencies do I miss.

Upvotes: 1

Views: 344

Answers (2)

svick
svick

Reputation: 244908

You're asking for dependencies, but you're not missing one. What you're missing is the Startup class, which either the blog you're following forgot to mention, or you didn't follow the directions.

The easiest way to create a new ASP.NET Core project is to run dotnet new -t web. The Startup class of that is here.

Upvotes: 1

Feasoron
Feasoron

Reputation: 3600

There really isn't going to be one. You may be able to find a tool like resharper that knows the official Microsoft packages and will tell you to "Microsoft.EntityFrameworkCore" or whatever you are missing. However, it's to general of a problem to be reliably solved. In your example, you're missing a class that is supposed to be defined in your code. It could also be solved by including a package that had a Startup defined. Even supposing that were the case, how would it know the right one to choose? There could be a lot of packages that implement a Startup class. Foo.Startup, Bar.Startup, Microsoft.CrossPlatform.StartUp - all of these could conceivably implement Startup in such a way that you code compiled. How would a tool know which of those suited your needs? In general you will be finding a library to include and adding it, not writing code and then looking for an implementation of what you need.

Upvotes: 1

Related Questions