question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

dotnet aspnet-codegenerator failing on Linux

See original GitHub issue

Hi,

I created a new webapi application with dotnet cli and I’m trying to scaffolding with dotnet aspnet-codegenerator but it’s failing.

Here’s the error:

Command Line: --project . controller -name PacientesController -m Paciente -outDir Controllers/
Microsoft (R) Build Engine version 15.1.548.43366
Copyright (C) Microsoft Corporation. All rights reserved.

/mnt/docs/dev/acs/acs.csproj : error MSB4057: The target "EvaluateProjectInfoForCodeGeneration" does not exist in the project.

Unhandled Exception: System.InvalidOperationException: Failed to get Project Context for /mnt/docs/dev/acs/acs.csproj.
  
   at Microsoft.Extensions.ProjectModel.MsBuildProjectContextBuilder.Build()
   at Microsoft.VisualStudio.Web.CodeGeneration.Tools.Program.GetProjectInformation(String projectPath, String configuration)
   at Microsoft.VisualStudio.Web.CodeGeneration.Tools.Program.BuildAndDispatchDependencyCommand(String[] args, String projectPath, String buildBasePath, String configuration, Boolean noBuild, ILogger logger)
   at Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args)
   at Microsoft.VisualStudio.Web.CodeGeneration.Tools.Program.Main(String[] args)

my .csproj

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>netcoreapp1.1.1</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <Folder Include="wwwroot\" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore" Version="1.1.1" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.2" />
    <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="1.1.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="1.1.1" PrivateAssets="All" />
    <PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="1.1.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="1.1.0" PrivateAssets="All" />
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="1.1.0" PrivateAssets="All" />
    <PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="1.1.0" />
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Msbuild" Version="1.1.0" />
  </ItemGroup>

  <ItemGroup>
    <DotNetCliToolReference Include="Microsoft.DotNet.Watcher.Tools" Version="1.0.0" />
    <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.0" />
    <DotNetCliToolReference Include="Microsoft.Extensions.SecretManager.Tools" Version="1.0.0" />
    <DotNetCliToolReference Include="Microsoft.Extensions.Caching.SqlConfig.Tools" Version="1.0.0" />
    <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.0" />
  </ItemGroup> 

</Project>

dotnet --info

.NET Command Line Tools (1.0.1)

Product Information:
 Version:            1.0.1
 Commit SHA-1 hash:  005db40cd1

Runtime Environment:
 OS Name:     opensuse
 OS Version:  20170331
 OS Platform: Linux
 RID:         opensuse.13.2-x64
 Base Path:   /opt/dotnet/sdk/1.0.1

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:21 (7 by maintainers)

github_iconTop GitHub Comments

6reactions
prafullbhosalecommented, Apr 11, 2017

@thild, I have found the issue. I will create a PR for the fix. In the meanwhile a workaround you can try is as below: Locate *.codegeneration.targets under your project_directory/obj/

Replace the below

<ImportGroup Condition=" '$(TargetFramework)' == '' AND '$(ExcludeRestorePackageImports)' != 'true' ">
    <Import Project="$(CodeGenerationTargetLocation)\buildMultiTargeting\microsoft.visualstudio.web.codegeneration.tools.targets" Condition="Exists('$(CodeGenerationTargetLocation)\buildCrossTargeting\microsoft.visualstudio.web.codegeneration.tools.targets')" />
  </ImportGroup>
  <ImportGroup Condition=" '$(TargetFramework)' != '' AND '$(ExcludeRestorePackageImports)' != 'true' ">
    <Import Project="$(CodeGenerationTargetLocation)\build\netstandard1.0\microsoft.visualstudio.web.codegeneration.tools.targets" Condition="Exists('$(CodeGenerationTargetLocation)\build\netstandard1.0\microsoft.visualstudio.web.codegeneration.tools.targets')" />
  </ImportGroup>

with

<ImportGroup Condition=" '$(TargetFramework)' == '' AND '$(ExcludeRestorePackageImports)' != 'true' ">
    <Import Project="$(CodeGenerationTargetLocation)\buildMultiTargeting\Microsoft.VisualStudio.Web.CodeGeneration.Tools.targets" Condition="Exists('$(CodeGenerationTargetLocation)\buildCrossTargeting\Microsoft.VisualStudio.Web.CodeGeneration.Tools.targets')" />
  </ImportGroup>
  <ImportGroup Condition=" '$(TargetFramework)' != '' AND '$(ExcludeRestorePackageImports)' != 'true' ">
    <Import Project="$(CodeGenerationTargetLocation)\build\netstandard1.0\Microsoft.VisualStudio.Web.CodeGeneration.Tools.targets" Condition="Exists('$(CodeGenerationTargetLocation)\build\netstandard1.0\Microsoft.VisualStudio.Web.CodeGeneration.Tools.targets')" />
  </ImportGroup>

Note this file gets generated when run scaffolding the first time on a project.

2reactions
prafullbhosalecommented, May 11, 2017

Closing this as the fix is available in version 1.0.1 of Microsoft.VisualStudio.Web.CodeGeneration.Tools You can update the version in the .csproj file

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

Feel free to reopen this if you still see the issue after upgrading.

Read more comments on GitHub >

github_iconTop Results From Across the Web

dotnet aspnet-codegenerator failing on Linux · Issue #444
Hi, I created a new webapi application with dotnet cli and I'm trying to scaffolding with dotnet aspnet-codegenerator but it's failing.
Read more >
c# - aspnet-codegenerator could not execute
"Could not execute because the specified command or file was not found. Possible reasons for this include: * You misspelled a built-in dotnet ......
Read more >
dotnet aspnet-codegenerator command
Description. The dotnet aspnet-codegenerator global command runs the ASP.NET Core code generator and scaffolding engine. Arguments.
Read more >
Scaffolding code generator does not work on Linux OS
It looks like we have a good news with this issue and it should be fixed in the latest dotnet-aspnet-codegenerator tool and Microsoft....
Read more >
NETSDK1005 – update dotnet aspnet-codegenerator – Do That
I had updated dotnet SDK and runtime but not aspnet-codegenerator (which ... this is some kind on Linux specific aspnet-codegenerator issue.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found