Skip to content
This repository has been archived by the owner on Apr 11, 2020. It is now read-only.

Microsoft.VisualStudio.Web.CodeGeneration.Tools has been deprecated in favor of dotnet-aspnet-codegenerator #1075

Open
AngelosP opened this issue Jun 5, 2018 · 8 comments

Comments

@AngelosP
Copy link
Contributor

AngelosP commented Jun 5, 2018

Microsoft.VisualStudio.Web.CodeGeneration.Tools has been deprecated in favor of https://www.nuget.org/packages/dotnet-aspnet-codegenerator/

@rudiv
Copy link

rudiv commented Jun 5, 2018

I'm not clear what effect this has (as it hasn't been explained in these announcements), but I have to say that this package was the devil. Right Click -> Add -> Controller from an MVC Project, which drags this package in, is the worst thing that I keep forgetting I shouldn't do. By doing so, I'm immediately adding around 20 useless DLLs to my Publish.

With that I'm pretty confident that if this is what I think it is (something that won't drag in actual build dependencies / references to generate a ~15 line file), I'm massively excited about this change 🎉

@MattJeanes
Copy link

Is this going to replace the automatic package addition in visual studio as described by @rudiv?

@cilerler
Copy link

cilerler commented Jun 6, 2018

@AngelosP so is this mean we can run the line below on CommandPrompt

dotnet tool install --global dotnet-aspnet-codegenerator

and then remove the line below from project files?

<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.4" />

@vverrastro
Copy link

Hi all,
when I try to install dotnet-aspnet-codegenerator in my netcoreapp 2.1 from nuget manager, I have the following error:

Error Package 'dotnet-aspnet-codegenerator 2.1.0' has a package type 'DotnetTool' that is not supported by project 'myproject'.

Anyone have the same error?

@seancpeters
Copy link

The dotnet aspnet-codegenerator global tool is only necessary to install when scaffolding from the command line. If you’re only scaffolding from Visual Studio, it is not necessary to install the global tool.

When scaffolding from Visual Studio, it’s no longer necessary to include the package reference to Microsoft.VisualStudio.Web.CodeGeneration.Tools. But scaffolding will still add the references needed by the generated content, as well as a reference to Microsoft.VisualStudio.Web.CodeGeneration.Design

If you want to scaffold from the command line, then the global tool should be installed from the command line, using the command:
dotnet tool install –global dotnet-aspnet-codegenerator

It should not be installed into any specific project via the nuget package manager in VS.

@rudiv
Copy link

rudiv commented Jun 9, 2018

Ah, so this doesn't actually fix the deployment issue wherein lots of further (unneeded) files are dragged in to the project? That must be Microsoft.VisualStudio.Web.CodeGeneration.Design that I was referring to.

@natemcmaster natemcmaster changed the title Microsoft.VisualStudio.Web.CodeGeneration.Tools has been deprecated in favor of https://www.nuget.org/packages/dotnet-aspnet-codegenerator/ Microsoft.VisualStudio.Web.CodeGeneration.Tools has been deprecated in favor of dotnet-aspnet-codegenerator Oct 29, 2018
@chrisckc
Copy link

chrisckc commented Nov 27, 2018

dotnet-aspnet-codegenerator behaves differently from the previous tool, here is an example:

In the previous tool the following would create a valid configuration:
dotnet new mvc --auth Individual
then run the scaffolder tool to create the Identity UI

However using the new tool:
dotnet tool install --global dotnet-aspnet-codegenerator --version 2.1.6

then:

dotnet new  mvc --auth Individual
dotnet-aspnet-codegenerator identity --force

All of the UI related setup is added under /Areas/Identity inside IdentityHostingStartup.cs and uses SqlServer rather then Sqlite, but Startup.cs is left untouched so the code generated by dotnet new mvc --auth Individual is left behind resulting in duplicated contexts and exception at runtime.

services.AddDbContext<ApplicationDbContext>(options =>
                options.UseSqlite(
                    Configuration.GetConnectionString("DefaultConnection")));
            services.AddDefaultIdentity<IdentityUser>()
                .AddEntityFrameworkStores<ApplicationDbContext>();

It seems that the new tool has been designed to add Identity to an existing non-identity enabled project, which seems to make sense, however the docs should cover this if not already.

EDIT: This is covered in the ScaffoldingReadme.txt

If your app was previously configured to use Identity, then you should remove the call to the AddIdentity method from your ConfigureServices method.

The only existing file touched by the new tool was appsettings.json to add a new connection string, which is why --force needed to be used.

@SagorFox
Copy link

Hi all,
when I try to install dotnet-aspnet-codegenerator in my netcoreapp 2.1 from nuget manager, I have the following error:

Error Package 'dotnet-aspnet-codegenerator 2.1.0' has a package type 'DotnetTool' that is not supported by project 'myproject'.

Anyone have the same error?

Yeap! I have got this error when I tried to load my project on another computer, every dependencies was unresolved such as NuGet and SDK. I just opened my project.csproj on Notepad and removed the CodeGenerator.Design from ItemGroup Tag and then reloaded the project in visual studio. My problem was solved.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants