Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is .NET CLI only for .NET Core?

Do I use the .NET CLI if I want to create an ASP.NET Core 1.0 app that uses the .NET Framework? Is .NET CLI only for the new .NET Core library or both Core and .NET 4.6?

like image 908
Sam Avatar asked Jul 06 '16 17:07

Sam


3 Answers

You can use dotnet cli for full framework apps and libraries as well. You just need to use the appropriate framework tag - for example "net46" to target .NET 4.6. You can target multiple frameworks, too:

For example, from my Noda Time library:

"frameworks": {
  "net45": {
    "frameworkAssemblies": {
      "System.Xml": "",
      "System.Numerics": ""
    }
  },
  "netstandard1.1": {
    "buildOptions": {
      "define": [ "PCL" ]
    },
    "dependencies": {
      "System.Diagnostics.Debug": "4.0.11",
      "System.Globalization": "4.0.11",
      "System.Linq": "4.1.0",
      "System.Resources.ResourceManager": "4.0.1",
      "System.Runtime.Extensions": "4.1.0",
      "System.Runtime.Numerics": "4.0.1",
      "System.Runtime.Serialization.Xml": "4.1.1",
      "System.Threading": "4.0.11",
      "System.Xml.XmlSerializer": "4.0.11"
    }
  }
}

The PCL preprocessor symbol will be renamed to "DOTNET_CORE" or similar at some point - it's only there because I have a bunch of code that uses it for conditional compilation back when I used to target portable class libraries.

You can still also target portable class libraries, by the way... so a single package can target many different versions.

like image 199
Jon Skeet Avatar answered Oct 22 '22 09:10

Jon Skeet


Do I use the CLI if I want to create an ASP.NET Core 1.0 app that uses the .NET Framework?

The .NET CLI is for either, the distinction is actually made in the project.json file. For example you can use the following command to compile/build the ASP.NET Core application while the application is actually targeting the full-framework:

dotnet build

Here is what an example project.json would look like targeting .NET 4.6.

{
  "frameworks": {
    "net46": { }
  }
}

For more details I always encourage people to refer to the documentation found here. Likewise, since this is open-source (which is amazing) you can look at the source to understand how it is that this is intended to be used.

like image 35
David Pine Avatar answered Oct 22 '22 08:10

David Pine


CLI is just tooling. What your application will use to run is not coupled to tooling (i.e. as long as the tooling is able to create the correct application for your target framework it does not matter how tooling runs). Rather, in your project.json file you specify the target framework in form of target framwork moniker (e.g. net451 for .NET Framework 4.5.1 or netcoreapp1.0 for .NET Core apps etc.)

like image 27
Pawel Avatar answered Oct 22 '22 10:10

Pawel