Razor 类库 MSBuild MSB4062 编译期间出错 [英] Razor Class Library MSBuild MSB4062 Error During Compile

查看:32
本文介绍了Razor 类库 MSBuild MSB4062 编译期间出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我构建一个引用 Razor 类库的 MVC 应用程序时,我试图弄清楚如何解决 MSB4062 错误.重现它的步骤包括创建一个新的 MVC 项目(运行dotnet new mvc"),创建一个新的 Razor 类库(运行dotnet new razorclasslib"),并通过将以下内容添加到 MVC 应用程序中csproj 文件:

I'm trying to figure out how to solve MSB4062 error when I'm building a MVC application that references a Razor class library. The steps to reproduce it involve creating a new MVC project (running "dotnet new mvc"), creating a new Razor Class Library (running "dotnet new razorclasslib"), and adding the class library to the MVC application by adding the following to the csproj file:

<ItemGroup>
    <ProjectReference Include="..LibraryLibrary.csproj" />
</ItemGroup>

一旦我尝试编译项目(我使用的是 Visual Studio Code),就会收到以下错误消息:

As soon as I try to compile the project (I'm using Visual Studio Code), I get the following error message:

C:Program FilesDotNETsdkNuGetFallbackFoldermicrosoft.aspnetcore.razor.design2.1.2uild etstandard2.0Microsoft.AspNetCore.Razor.Design.CodeGeneration.targets(69,5):错误 MSB4062:无法从程序集 C:Program FilesDotNETsdkNuGetFallbackFoldermicrosoft.aspnetcore.razor.design2.1.2uild etstandard2 加载Microsoft.AspNetCore.Razor.Tasks.RazorTagHelper"任务.0.... asks etstandard2.0Microsoft.AspNetCore.Razor.Tasks.dll.已加载同名程序集 确认声明正确,程序集及其所有依赖项都可用,并且任务包含实现 Microsoft.Build.Framework.ITask 的公共类.[C:UsersuserprofileDevelopmentApplicationApplication.csproj]

C:Program FilesDotNETsdkNuGetFallbackFoldermicrosoft.aspnetcore.razor.design2.1.2uild etstandard2.0Microsoft.AspNetCore.Razor.Design.CodeGeneration.targets(69,5): error MSB4062: The "Microsoft.AspNetCore.Razor.Tasks.RazorTagHelper" task could not be loaded from the assembly C:Program FilesDotNETsdkNuGetFallbackFoldermicrosoft.aspnetcore.razor.design2.1.2uild etstandard2.0.... asks etstandard2.0Microsoft.AspNetCore.Razor.Tasks.dll. Assembly with same name is already loaded Confirm that the declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask. [C:UsersuserprofileDevelopmentApplicationApplication.csproj]

真正奇怪的部分是,如果我然后删除 csproj 文件中的 ProjectReference 条目,编译 MVC 应用程序(不带库),然后重新添加 ProjectReference 条目,则整个项目(带库)编译正常.但是,一旦我清理了 MVC 应用程序或库,错误就会回来.

The really strange part is that if I then remove the ProjectReference entry in the csproj file, compile the MVC application (without the library), then re-add the ProjectReference entry, the whole project (with library) compiles fine. However, as soon as I clean either the MVC application or library the error comes back.

推荐答案

将以下内容添加到 razor 类库的 csproj 文件修复了该问题:

Adding the following to the razor class library's csproj file fixed the issue:

<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.1.2" PrivateAssets="All" />

默认情况下,应用程序的 csproj 文件中已经存在类似的引用......也许版本不匹配?

A similar reference already exists by default in the application's csproj file ... maybe there was a version mismatch?

这篇关于Razor 类库 MSBuild MSB4062 编译期间出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆