Trying out “dotnet new” template updates and csproj with VS2017 (by Scott Hanselman)

I updated my Visual Studio 2017 RC installation today. Here’s the release notes. You just run "Visual Studio Installer" if you’ve already got a version installed and it updates. The updating processes reminds me a little of how Office 365 updates itself. It’s not as scary as VS updates of the past. You can download the VS2017 RC at https://www.visualstudio.com and it works side by side with your existing installs. I haven’t had any issues yet.

It also added/updated a new .NET Core SDK. I am a fan of the command line "dotnet.exe" tooling and I’ve been pushing for improvements in that experience. A bunch of stuff landed in this update that I’ve been waiting for. Here’s dotnet new:

C:\Users\scott\Desktop\poop> dotnet newTemplate Instantiation Commands for .NET Core CLI.Usage: dotnet new [arguments] [options]Arguments:  template  The template to instantiate.Options:  -l|--list         List templates containing the specified name.  -lang|--language  Specifies the language of the template to create  -n|--name         The name for the output being created. If no name is specified, the name of the current directory is used.  -o|--output       Location to place the generated output.  -h|--help         Displays help for this command.  -all|--show-all   Shows all templatesTemplates                                 Short Name      Language      Tags--------------------------------------------------------------------------------------Console Application                       console         [C#], F#      Common/ConsoleClass library                             classlib        [C#], F#      Common/LibraryUnit Test Project                         mstest          [C#], F#      Test/MSTestxUnit Test Project                        xunit           [C#], F#      Test/xUnitEmpty ASP.NET Core Web Application        web             [C#]          Web/EmptyMVC ASP.NET Core Web Application          mvc             [C#], F#      Web/MVCWeb API ASP.NET Core Web Application      webapi          [C#]          Web/WebAPISolution File                             sln                           SolutionExamples:    dotnet new mvc --auth None --framework netcoreapp1.0    dotnet new console --framework netcoreapp1.0    dotnet new --help

There is a whole new templating engine now. The code is here https://github.com/dotnet/templating and you can read about how to make your own templates or on the wiki.

I did a "dotnet new xunit" and it made the csproj file and a Unit Test. Here’s what’s inside the csproj:

<Project Sdk="Microsoft.NET.Sdk">  <PropertyGroup>    <OutputType>Exe</OutputType>    <TargetFramework>netcoreapp1.0</TargetFramework>  </PropertyGroup>  <ItemGroup>    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0-preview-20170123-02" />    <PackageReference Include="xunit" Version="2.2.0-beta5-build3474" />    <PackageReference Include="xunit.runner.visualstudio" Version="2.2.0-beta5-build1225" />  </ItemGroup></Project>

That’s not too bad. Here’s a a library with no references:

<Project Sdk="Microsoft.NET.Sdk">  <PropertyGroup>    <TargetFramework>netstandard1.4</TargetFramework>  </PropertyGroup></Project>

Note there’s no GUIDs in the csproj. Sweet.

Remember also that there was talk that you wouldn’t have to edit your csproj manually? Check this out:

C:\Users\scott\Desktop\poop\lib> dotnet add package Newtonsoft.JsonMicrosoft (R) Build Engine version 15.1.545.13942Copyright (C) Microsoft Corporation. All rights reserved.  Writing C:\Users\scott\AppData\Local\Temp\tmpBA1D.tmpinfo : Adding PackageReference for package 'Newtonsoft.Json' into project 'C:\Users\scott\Desktop\poop\lib\lib.csproj'.log  : Restoring packages for C:\Users\scott\Desktop\poop\lib\lib.csproj...info :   GET https://api.nuget.org/v3-flatcontainer/newtonsoft.json/index.jsoninfo :   OK https://api.nuget.org/v3-flatcontainer/newtonsoft.json/index.json 1209msinfo :   GET https://api.nuget.org/v3-flatcontainer/newtonsoft.json/9.0.1/newtonsoft.json.9.0.1.nupkginfo :   OK https://api.nuget.org/v3-flatcontainer/newtonsoft.json/9.0.1/newtonsoft.json.9.0.1.nupkg 181msinfo : Package 'Newtonsoft.Json' is compatible with all the specified frameworks in project 'C:\Users\scott\Desktop\poop\lib\lib.csproj'.info : PackageReference for package 'Newtonsoft.Json' version '9.0.1' added to file 'C:\Users\scott\Desktop\poop\lib\lib.csproj'.

Doing "dotnet add package foo.bar" automatically gets the package from NuGet and adds it to your csproj. Just like doing "Add NuGet Package" (or add reference) in Visual Studio. You don’t even have to open or look at your csproj.

I’m going to keep digging into this. We’re getting into a nice place where someone could easily make a custom template then "nuget in" that templates then "File | New | Your Company’s Template" without needed yeoman, etc.

Please shared your feedback:

Also, be sure to check out the new and growing Docs site at https://docs.microsoft.com/en-us/dotnet

Sponsor: Track every change to your database. See who made changes, what they did, & why, with SQL Source Control. Get a full version history in your source control system. See how with Red Gate’s SQL Source Control.

© 2016 Scott Hanselman. All rights reserved.





Bir Cevap Yazın

E-posta hesabınız yayımlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir

TOP