Scaffolding: dotnet aspnet-codegenerator failing on Linux

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

About this issue

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

Most upvoted comments

@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.

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.

@prafullbhosale Your fix works on Linux too. Just a casing issue? Thanks.

@prafullbhosale I can confirm your fix works on OSX 😃 Thanks very much