I find that The package:Microsoft.VisualStudio.CodeGeneration has over 20,000,000 downloads in the nuget.but I can not find any doc.
how to use it?
any articles about it?
What does this package do
Basically, the package offers a single command to generate code:
dotnet aspnet-codegenerator {name}
You can find the source code here.
How to use the package
We don't use the Microsoft.VisualStudio.Web.CodeGeneration directly unless we're creating a new command to generate code.
Because it is a command library for generic purpose, concrete commands are defined in other packages. For example, the dotnet aspnet-codegenerator controller command is defined in Microsoft.VisualStudio.Web.CodeGenerators.Mvc. And the command dotnet aspnet-codegenerator identity is also defined in the CG.MVC package.
Usually , since this package is a generic purpose library, you won't reference this package directly. Instead, You'll add the package Microsoft.VisualStudio.Web.CodeGeneration.Design. Be aware the Microsoft.VisualStudio.Web.CodeGeneration.Design package has a dependency on Microsoft.VisualStudio.Web.CodeGenerators.Mvc, and the Microsoft.VisualStudio.Web.CodeGenerators.Mvc depends on Microsoft.VisualStudio.Web.CodeGeneration:
Microsoft.VisualStudio.Web.CodeGeneration.Design
|
|(depends on)
|-----------> Microsoft.VisualStudio.Web.CodeGenerators.Mvc
|
|(depends on)
|-----------> Microsoft.VisualStudio.Web.CodeGeneration
Be aware the Microsoft.VisualStudio.Web.CodeGeneration.Design is automatically added into your dependencies when you use Visual Studio to scaffold a controller/identity.
If you're using a VSCode/CLI, you need to manually add such a package reference. See https://learn.microsoft.com/en-us/aspnet/core/tutorials/first-mvc-app/adding-model?view=aspnetcore-3.0&tabs=visual-studio-code#add-nuget-packages
What #itminus says. I think the reason it has so many downloads is from the clear error message when you try to use dotnet aspnet-codegenerator without Microsoft.VisualStudio.Web.CodeGeneration.Design NuGet.
As of 2021-08-27 it has 90,672,569 total downloads.
https://www.nuget.org/packages/Microsoft.VisualStudio.Web.CodeGeneration.Design/
Example error:
Building project ...
Scaffolding failed.
Add Microsoft.VisualStudio.Web.CodeGeneration.Design package to the project as a
NuGet package reference. To see more information, enable tracing by setting
environment variable 'codegen_trace' = 1.
Related
I am scaffolding a local login identity page in into a asp.net core solution that already has default identity. I am doing this in order to customize my login page.
I have successfully done this using two test apps which use the same base code with progressively more packages installed) before attempting this on my final.
For my app, when I issue the following command, I'm getting this error:
PM> dotnet-aspnet-codegenerator identity --dbContext ApplicationDbContext
Failed to get Project Context for C:\Users\...\rollbase.csproj.
To see more information, enable tracing by setting environment variable 'codegen_trace' = 1
There is no information about 'codegen_trace' in docs.
I have searched and found a lot of references to this error. But can't find anything for:
What is the 'Project Context'
How do I use a 'codegen_trace'
The solution builds successfully.
I have been very careful keeping track of the packages involved
Microsoft.VisualStudio.Web.CodeGeneration.Design
Microsoft.AspNetCore.Identity.EntityFrameworkCore
Microsoft.AspNetCore.Identity.UI
Azure.Identity
Using
<TargetFramework>net5.0</TargetFramework>
dotnet-aspnet-codegenerator' (version '5.0.0')
dotnet sdk 5.0.403
Microsoft.NETCore.App 5.0.12
Most posts talk of rolling back the tool version/packages etc. I was wanting to know if anyone out there can actually point to a solid debug strategy.
I am adding info to this question below
Using help provided - output from codegen_trace
Microsoft.Extensions.ProjectModel.MsBuildProjectContextBuilder.Build()
/_/src/Ext.ProjectModel.MsBuild.Sources/MsBuildProjectContextBuilder.cs:line 56
At Microsoft.VisualStudio.Web.CodeGeneration.Tools.Program
.GetProjectInformation(String projectPath, String configuration) in
/_/src/dotnet-aspnet-codegenerator/Program.cs:line 290
At Microsoft.VisualStudio.Web.CodeGeneration.Tools.Program
.BuildAndDispatchDependencyCommand(String[] args,
String projectPath, String buildBasePath, String configuration, Boolean noBuild, ILogger logger)
in /_/src/dotnet-aspnet-codegenerator/Program.cs:line 173
Microsoft.VisualStudio.Web.CodeGeneration.Tools.Program
.<>c__DisplayClass19_0.<Execute>b__0() in
/_/src/dotnet-aspnet-codegenerator/Program.cs:line 129
From this output it looks like a problem in the installed package Microsoft.VisualStudio.Web.CodeGeneration.Tools 5.0.2
I have tried to update the package to 6.0,0 in Visual Studio 2019 (latest) but get the following:
NU1202: Package Microsoft.VisualStudio.Web.CodeGeneration.Design 6.0.0 is not compatible with net5.0 (.NETCoreApp,Version=v5.0). Package Microsoft.VisualStudio.Web.CodeGeneration.Design 6.0.0 supports: net6.0 (.NETCoreApp,Version=v6.0)
I looked at the github repo for this project but could not find any documentation regarding compatibility with .NETCoreApp,Version=v5.0
With reference to the original error message:
PM> dotnet-aspnet-codegenerator identity --dbContext ApplicationDbContext
Failed to get Project Context for C:\Users\...\rollbase.csproj
I have compared the .csproj files for the project where codegenerator works against the one where codegenerator fails to get Project Context.
The main difference is in the Property Group.
The codegnerator works:
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<UserSecretsId>aspnet-testbase1-57C4221E-46E9-4653-A734-4C412F7C523D</UserSecretsId>
</PropertyGroup>
Where Project Context not found:
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<UserSecretsId>aspnet-rollbase-6D7D2449-EB25-45CE-A8D3-EDAB69CDCAB3</UserSecretsId>
<RootNamespace></RootNamespace>
<RunAnalyzersDuringBuild>false</RunAnalyzersDuringBuild>
<AssemblyName />
<PackageId />
<EnableNETAnalyzers>false</EnableNETAnalyzers>
</PropertyGroup>
The best way to understanding the codegen_trace environment variable and it's output is reading the source code.
To enable the Trace logs, set the codegen_trace environment variable before you run dotnet-aspnet-codegenerator:
Command Prompt
SET codegen_trace=1
PowerShell
$env:codegen_trace=1
Bash/Zsh/Fish
export codegen_trace=1
The Project Context means the context of the project information. Most of the project information included in *.csproj file. Your problem is very possible that your project can't build successfully. You have to make sure your project is buildable.
For your dotnet-aspnet-codegenerator identity --dbContext ApplicationDbContext command, you at least need to install the following packages to get things right.
dotnet add package Microsoft.EntityFrameworkCore.Design
dotnet add package Microsoft.EntityFrameworkCore.SqlServer
dotnet add package Microsoft.AspNetCore.Identity.UI
dotnet add package Microsoft.VisualStudio.Web.CodeGeneration.Design
Please check the version of your code generator CLI tool version is the same as with your.NET version. You need to set the codegen_trace as an Environmental variable like this if you're in Linux or mac
codegen_trace=1
If you're using Powershell you can set it like this.
$env:codegen_trace=1
There is a GitHub open issue related to this. Please check the solutions on that as well. - https://github.com/dotnet/Scaffolding/issues/1388
I edited the project file PropertyGroup section. From what it was (see additional info in question above) to:
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<UserSecretsId>aspnet-rollbase-6D7D2449-EB25-45CE-A8D3-EDAB69CDCAB3</UserSecretsId>
</PropertyGroup>
Identity files were scaffolded using:
dotnet-aspnet-codegenerator identity --dbContext ApplicationDbContext
[Trace]: Command Line: identity --dbContext ApplicationDbContext
Building project ...
[Trace]: Command Line: --no-dispatch --port-number 52819 identity --dbContext ApplicationDbContext --dispatcher-version 5.0.0+a93dad81ee7f820d8e33d3f91e066ef68053d004
Finding the generator 'identity'...
Running the generator 'identity'...
...etc...
This use case might be a bit off-label, but I'm hoping someone can help me...
For a number of years I've maintained a "library" of MSBuild commands -- in a file we'll call CommonTasks.targets, distributed through our internal NuGet server -- that handles various tasks needed by my company's projects. For the last few years I've utilized GitVersion v3 with it, both for generating the library's own NuGet package version numbers as well as utilizing GitVersion's GetVersion MSBuild target directly (e.g., when generating a corresponding git tag), to avoid needing to extract the GitVersion-generated version from the dependent project's assembly, post-build.
Previously (with GitVersion v3), all that was required was for my CommonTasks.targets file to import the GitVersionTask.targets file located in GitVersion's NuGet package at \build\dotnet\GitVersionTasks.targets. This targets file in turn executed the necessary UsingTask commands (particularly GitVersionTask.GetVersion) which then let me call <GetVersion ...> in my own .targets file after the import.
With v4, GitVersionTask has introduced a dependency on UtilPack.NuGet.MSBuild (which I gather helps with various NuGet commands). To start with, that meant that I needed to import its UtilPack.NuGet.MSBuild.props file, or GitVersionTask wouldn't load at all. However, having done that, I now get unexpected errors attempting to call GetVersion from within an MSBuild file. Seemingly, the GetVersion target now attempts to query all my defined NuGet repositories (nuget.org, local caches, our company server, etc.) for the packaged version of my library, and at the end I'm greeted with this error:
MSBUILD : NuGetTaskRunnerFactory error NR0001: [NuGet Error]: Unable to find package CommonTasks with version
(>= 1.37.0-gitversiontask4-0001) [C:\redacted\CommonTasks\Build.proj]
MSBUILD : NuGetTaskRunnerFactory error NR0001: - Found 108 version(s) in Source1 [ Nearest version: 1.36.3 ] [C:\redacted\CommonTasks\Build.proj]
MSBUILD : NuGetTaskRunnerFactory error NR0001: - Found 42 version(s) in Source2 [ Nearest version: 1.36.3 ] [C:\redacted\CommonTasks\Build.proj]
MSBUILD : NuGetTaskRunnerFactory error NR0001: - Found 0 version(s) in Microsoft Visual Studio Offline Packages [C:\redacted\CommonTasks\Build.proj]
MSBUILD : NuGetTaskRunnerFactory error NR0001: - Found 0 version(s) in nuget.org [C:\redacted\CommonTasks\Build.proj]
MSBUILD : Task factory error NMSBT003: Failed to find main package CommonTasks#. [C:\redacted\CommonTasks\Build.proj(47,9): error MSB4175: The task factory "Ut
ilPack.NuGet.MSBuild.NuGetTaskRunnerFactory" could not be loaded from the assembly "C:\redacted\CommonTasks\packages\UtilPack.NuGet.MSBuild.2.7.0\build\\net46\UtilPack.NuGet.MSBuild.dll". Object ref
erence not set to an instance of an object.
What I don't get is why it's attempting NuGet retrievals at all, and, even if that's the new default behavior, I don't know a way to disable that, or barring that, I don't know why it's not working. I assume the error must have something to do with this not being a normal .NET project (i.e., with no source code aside from a .targets file, no .csproj file, etc.). But my library is used by many normal .NET projects, which themselves use GitVersionTask to auto-version their assemblies.
For now I've pinned my library to GitVersionTask v3, but would very much like to figure out how to allow it to use v4 as I'd been using v3 previously. I could likely switch to using the GitVersion.CommandLine package instead, and parsing its output, but I ultimately do need these GitVersion-generated versions as MSBuild properties in order to use them as intended. And with dependent projects also using GitVersionTask (not the CLI), it's convenient to be able to use a single package for both.
Is there a way to fix what I'm doing with GitVersionTask v4, or some completely different (perhaps more elegant) way to achieve what I'm trying to do?
I upgraded Microsoft.AspNetCore from 2.0.3 to 2.0.5 and my WebAPI project, although running successfully locally, fails to start in production (IIS). Everything was fine in production until this upgrade. The error message produced in the log directory is as follows:
Error:
An assembly specified in the application dependencies manifest (MyProject.WebAPI.deps.json) was not found:
package: 'Microsoft.AspNetCore.Mvc.Abstractions', version: '2.0.2'
path: 'lib/netstandard2.0/Microsoft.AspNetCore.Mvc.Abstractions.dll'
This assembly was expected to be in the local runtime store as the application was published using the following target manifest files:
aspnetcore-store-2.0.5.xml
Could someone explain to me the details of exactly what this means? I assume it's a version mismatch of sorts, but why is this occurring? I thought the latest stable releases of NuGet packages weren't supposed to have such issues.
I was able to resolve the issue by downgrading Microsoft.AspNetCore.All from 2.0.5 to 2.0.3, but would like to find a better solution to the issue so I can use the most up-to-date version of this package.
Development machines usually have the SDK installed but on production the runtime only.
Add the following to your .csproj file and publish again.
<PropertyGroup>
<PublishWithAspNetCoreTargetManifest>false</PublishWithAspNetCoreTargetManifest>
</PropertyGroup>
Sometimes this is related to the Startup Project, For example if the migration is a class library in Azure Functions project. You have to make sure when you run Add-Migration while the EF Library project is selected as Startup Project.
For me, the marked answer didn't solve the issue. My issue was when trying to Add-Migration
Add-Migration -Name initial-migration -Context Mysln.Data.MyDbContext -StartupProject Mysln -Project Mysln.Core
And the error was like this:
I solved it by downgrading all my Entityframework packages to 2.0.0 instead of the latest 2.2.0-preview one.
If you have more than one project in your solution like me:
and if you want to scaffold dbcontext in your "non startup" project (InstantOrder.Functions.Data in my case)
then you should add the -StartupProject parameter of the Scaffold-DbContext command like this -
Scaffold-DbContext "Server=..." -Project InstantOrder.Functions.Data -StartupProject InstantOrder.Functions.Data
I know this may be old, but just in case it can help some one else, this one worked for me:
Adding:
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
To the PropertyGroup in the .csproj file.
To solve the first half of the error message, An assembly specified in the application dependencies manifest (…) was not found be sure to always use the publish output when deploying to a target sever.
For a self-contained application it can be found in
bin\Release\netcoreapp2.0\win81-x64\publish
or for framework-dependent deployments in
bin\Release\netcoreapp2.0\publish
The output in the directories above are meant to be used in development only, since they are specific to machine and user configuration built with.
Taken from a related answer.
2 cents: If you just take from the build folder, the dlls for the dependency aren't provided. If you publish the folder, they are. This was the fix for me.
I had this error however my solution was somewhat different from what was posted above. My problem was that I was deploying via a zip file and while building the zip file I wasn't including sub directories therefore required files were not being included.
So if you are publishing via a zip file make sure to include all sub folders while building the zip.
I got this error while running Scaffold-DbContext command on the Library project.
Solution:
Remove the Azure Function project from the solution, and then run this command.
After that, use add an existing project feature to add the Azure Function project again in the solution.
The correct .NET Core runtime was not installed on my PC. I had NETCore.App 2.1 and 2.2, but the project was targeted to 2.0.
dotnet --list-runtimes
I installed the correct runtime from the dot.net site and it resolved the issue.
In most case you get that error because there's misalignment of versions.
I changed the Microsoft.VisualStudio.Web.CodeGeneration.Design version, an it worked.
Before
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.0" />
After
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.4" />
This happened to me when I published my Lambda to AWS after renaming the project. I deleted both the obj and bin folders, rebuilt, republished and that fixed it.
I changed filters in Yaml.
Had projects called TestHelper etc...
Testrunner tried to run projects without tests, and the build was flagged as failed.
Added:
!**\*Helper*.*
To:
- task: DotNetCoreCLI#2
inputs:
command: 'test'
projects: |
**\*test*.dll
!**\*TestAdapter.dll
!**\obj\**
!**\*TestPlatform*.dll
!**\*Testing*.*
!**\*TestHost*.*
!**\*Helper*.*
I am working on an project and tried know to activate the migration but when I open the Nugget package console and enter “enable-migrations myProjectName” I get the massage “The term 'Enable-Migrations' is not recognized as the name of a cmdlet”. First I thought that I have to add an extra line in my project.json under commands, so I added “"ef": "EntityFramework.Commands" but that didn’t do the trick.”
Would be grateful for any pointers.
You did mention you are using the project.json file making me believe you are using the default ASP.NET 5 template which uses EF7 .
You can verify this by looking in your project.json at the version number.
Mine for example is:
"EntityFramework.Commands": "7.0.0-beta8",
"EntityFramework.SqlServer": "7.0.0-beta8",
or in your Package Manager Console type in:
get-command -module entityframework
which will give you the available commands you can use. From the above you can see I am using Entity Framework 7.
Enable-Migrations is not listed in the commands and that is the reason you are getting the error:
The term 'Enable-Migrations' is not recognized as the name of a cmdlet
If you wish to rather use EF6 instead you would have to remove those entries in your project.json and you can add via nuget or the package manager console EF6. Just keep in mind if you use EF6 the ASP.NET 5 Identity 3 will break as it is dependent on EF7.
The command Enable-Migrations does not exist in Entity Framework 7 like it did in previous Entity framework versions.
In EF7 the task of creating the migrations folder is now combined with the Add-Migration command.
See below for the Add-Migration command differences between EF6 and EF7:
When I create new project, create a new control have no problem. But when I'm using TFS in Visual Studios 2012 to get the latest code. All code is update, I cannot create new controller. This is my alert error from VS
could not load file or assembly'System.web.mvc, vesion = 3.0.0.0,culture = neutral, pulbickeytoken = 31bf3856ad364e35' or more of its this system cannot find the file specified.
Looks like you have a missing reference to System.Web.Mvc. Got to the "References" part of your project and add the missing reference.
Alternatively you could add the relevant System.Web.Mvc.Extensions Mvc 4 NuGet package which should add all references that your solution might be missing.
There is a discrepancy in your question between the error and your tag of MVC-4. So assuming you are aiming to use MVC 4.
In Visual Studio, go to the Package Manager Console via Tools -> Library Package Manager -> Package Manager Console. and run the following commands with the source : nuget.org as answered by Shiva in a Entity Framework question.
Edit:
Uninstall the previous version of MVC 3.0 and all references to it.
Uninstall-Package Microsoft.AspNet.Mv -Force
Upgrade to MVC 4.0 to match the tag you've added to the
question
Install-Package Microsoft.AspNet.Mvc -Version 4.0.30506
Check that Entity Framework is installed. Check the project file (*.csproj, *.vbproj) references by Right clicking the project file and opening it in a text editor such as notepad++.
Rebuild or Clean (optional) your project. When you have a full compile of the project such as getting the code from TFS, it will check all the references and throw this exception. When you compile the project again this error will most likely not appear as you are not doing a full compile.
Check the TFS version of the project file for any discrepancies.
I got the same problem, the cause was a "Security Update". After this update Project references to System.Web.Mvc.dll are no longer resolved because the assembly version of System.Web.Mvc.dll was incremented.
There are two ways to solve this issue, by installing a nuguet package or by manually updating the reference to System.Web.MVC.dll (don’t use the one in the GAC)
This blog post contains a detailed explanation:
http://blogs.msdn.com/b/webdev/archive/2014/10/16/microsoft-asp-net-mvc-security-update-broke-my-build.aspx