[备忘] 解决 rzc discover exited with code -2147450730 问题
现象:
本地可以正常编译和使用,用 Azure DevOps 进行 CI 时出错
重现:
项目代码:
<Project Sdk="Microsoft.NET.Sdk.Razor"> <PropertyGroup> <TargetFrameworks>netcoreapp3.1</TargetFrameworks> ...
YAML 配置:
trigger: - master pool: vmImage: 'windows-latest' variables: solution: '**/Senparc.Xncf.WeixinManager.sln' buildPlatform: 'Any CPU' buildConfiguration: 'Release' steps: - task: UseDotNet@2 displayName: 'Use .NET SDK 3.1' inputs: version: '3.1.x' packageType: 'sdk' - task: DotNetCoreCLI@2 displayName: Build inputs: command: build projects: '**/Senparc.Xncf.WeixinManager.sln' arguments: '--configuration Release'
编译日志记录:
Starting: Build ============================================================================== Task : .NET Core Description : Build, test, package, or publish a dotnet application, or run a custom dotnet command Version : 2.187.0 Author : Microsoft Corporation Help : https://docs.microsoft.com/azure/devops/pipelines/tasks/build/dotnet-core-cli ============================================================================== C:\Windows\system32\chcp.com 65001 Active code page: 65001 Info: .NET Core SDK/runtime 2.2 and 3.0 are now End of Life(EOL) and have been removed from all hosted agents. If you're using these SDK/runtimes on hosted agents, kindly upgrade to newer versions which are not EOL, or else use UseDotNet task to install the required version. C:\hostedtoolcache\windows\dotnet\dotnet.exe build D:\a\1\s\src\Senparc.Xncf.WeixinManager.sln "-dl:CentralLogger,\"D:\a\_tasks\DotNetCoreCLI_5541a522-603c-47ad-91fc-a4b1d163081b\2.187.0\dotnet-build-helpers\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll\"*ForwardingLogger,\"D:\a\_tasks\DotNetCoreCLI_5541a522-603c-47ad-91fc-a4b1d163081b\2.187.0\dotnet-build-helpers\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll\"" --configuration Release Microsoft (R) Build Engine version 16.10.2+857e5a733 for .NET Copyright (C) Microsoft Corporation. All rights reserved. Determining projects to restore... Restored D:\a\1\s\src\Senparc.Xncf.WeixinManager\Senparc.Xncf.WeixinManager.csproj (in 1.12 min). Restored D:\a\1\s\src\Senparc.Xncf.WeixinManager.Tests\Senparc.Xncf.WeixinManager.Tests.csproj (in 1.12 min). ##[warning]C:\hostedtoolcache\windows\dotnet\sdk\5.0.302\Sdks\Microsoft.NET.Sdk.Razor\build\netstandard2.0\Sdk.Razor.CurrentVersion.targets(416,5): Warning RAZORSDK1006: Detected Razor language version downgrade. This is typically caused by a reference to the Microsoft.AspNetCore.Razor.Design package. Consider removing this package reference. C:\hostedtoolcache\windows\dotnet\sdk\5.0.302\Sdks\Microsoft.NET.Sdk.Razor\build\netstandard2.0\Sdk.Razor.CurrentVersion.targets(416,5): warning RAZORSDK1006: Detected Razor language version downgrade. This is typically caused by a reference to the Microsoft.AspNetCore.Razor.Design package. Consider removing this package reference. [D:\a\1\s\src\Senparc.Xncf.WeixinManager\Senparc.Xncf.WeixinManager.csproj] ##[warning]src\Senparc.Xncf.WeixinManager\Models\DatabaseModel\Dto\WeixinUserDto.cs(63,23): Warning CS0108: 'WeixinUserDto.Remark' hides inherited member 'DtoBase.Remark'. Use the new keyword if hiding was intended. D:\a\1\s\src\Senparc.Xncf.WeixinManager\Models\DatabaseModel\Dto\WeixinUserDto.cs(63,23): warning CS0108: 'WeixinUserDto.Remark' hides inherited member 'DtoBase.Remark'. Use the new keyword if hiding was intended. [D:\a\1\s\src\Senparc.Xncf.WeixinManager\Senparc.Xncf.WeixinManager.csproj] ##[warning]src\Senparc.Xncf.WeixinManager\Models\DatabaseModel\WeixinUser.cs(71,23): Warning CS0108: 'WeixinUser.Remark' hides inherited member 'EntityBase<int>.Remark'. Use the new keyword if hiding was intended. D:\a\1\s\src\Senparc.Xncf.WeixinManager\Models\DatabaseModel\WeixinUser.cs(71,23): warning CS0108: 'WeixinUser.Remark' hides inherited member 'EntityBase<int>.Remark'. Use the new keyword if hiding was intended. [D:\a\1\s\src\Senparc.Xncf.WeixinManager\Senparc.Xncf.WeixinManager.csproj] ##[warning]src\Senparc.Xncf.WeixinManager\Areas\Admin\Pages\WeixinManager\WeixinUser\Index.cshtml.cs(44,42): Warning CS1998: This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread. D:\a\1\s\src\Senparc.Xncf.WeixinManager\Areas\Admin\Pages\WeixinManager\WeixinUser\Index.cshtml.cs(44,42): warning CS1998: This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread. [D:\a\1\s\src\Senparc.Xncf.WeixinManager\Senparc.Xncf.WeixinManager.csproj] ##[warning]src\Senparc.Xncf.WeixinManager\Register.cs(189,13): Warning CS0162: Unreachable code detected D:\a\1\s\src\Senparc.Xncf.WeixinManager\Register.cs(189,13): warning CS0162: Unreachable code detected [D:\a\1\s\src\Senparc.Xncf.WeixinManager\Senparc.Xncf.WeixinManager.csproj] ##[warning]src\Senparc.Xncf.WeixinManager\Register.Middleware.cs(83,46): Warning CS0168: The variable 'ex' is declared but never used D:\a\1\s\src\Senparc.Xncf.WeixinManager\Register.Middleware.cs(83,46): warning CS0168: The variable 'ex' is declared but never used [D:\a\1\s\src\Senparc.Xncf.WeixinManager\Senparc.Xncf.WeixinManager.csproj] ##[warning]src\Senparc.Xncf.WeixinManager\Areas\Admin\Pages\WeixinManager\WeixinUser\Index.cshtml.cs(28,21): Warning CS0414: The field 'WeixinUser_IndexModel.pageCount' is assigned but its value is never used D:\a\1\s\src\Senparc.Xncf.WeixinManager\Areas\Admin\Pages\WeixinManager\WeixinUser\Index.cshtml.cs(28,21): warning CS0414: The field 'WeixinUser_IndexModel.pageCount' is assigned but its value is never used [D:\a\1\s\src\Senparc.Xncf.WeixinManager\Senparc.Xncf.WeixinManager.csproj] ##[warning]CSC(0,0): Warning AD0001: Analyzer 'Microsoft.AspNetCore.Mvc.Analyzers.TopLevelParameterNameAnalyzer' threw an exception of type 'System.NullReferenceException' with message 'Object reference not set to an instance of an object.'. CSC : warning AD0001: Analyzer 'Microsoft.AspNetCore.Mvc.Analyzers.TopLevelParameterNameAnalyzer' threw an exception of type 'System.NullReferenceException' with message 'Object reference not set to an instance of an object.'. [D:\a\1\s\src\Senparc.Xncf.WeixinManager\Senparc.Xncf.WeixinManager.csproj] It was not possible to find any compatible framework version The framework 'Microsoft.NETCore.App', version '2.0.9' was not found. - The following frameworks were found: 5.0.8 at [C:\hostedtoolcache\windows\dotnet\shared\Microsoft.NETCore.App] You can resolve the problem by installing the specified framework and/or SDK. The specified framework can be found at: - https://aka.ms/dotnet-core-applaunch?framework=Microsoft.NETCore.App&framework_version=2.0.9&arch=x64&rid=win10-x64 ##[error]C:\Users\VssAdministrator\.nuget\packages\microsoft.aspnetcore.razor.design\2.2.0\build\netstandard2.0\Microsoft.AspNetCore.Razor.Design.CodeGeneration.targets(79,5): Error : rzc discover exited with code -2147450730. C:\Users\VssAdministrator\.nuget\packages\microsoft.aspnetcore.razor.design\2.2.0\build\netstandard2.0\Microsoft.AspNetCore.Razor.Design.CodeGeneration.targets(79,5): error : rzc discover exited with code -2147450730. [D:\a\1\s\src\Senparc.Xncf.WeixinManager\Senparc.Xncf.WeixinManager.csproj]
尝试解决方案:
- 项目文件设置添加:<RazorLangVersion>3.0</RazorLangVersion> ,无效,引发其他错误:MSB4044 未给任务“ComputeCssScope”的必需参数“TargetName”赋值。
- 修改项目文件配置 Microsoft.NET.Sdk.Razor 为 Microsoft.NET.Sdk,集成后无法读取 Razor 页面
- 项目添加引用 <PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="3.1.1" />,无效
最终解决方案:
在 .csproj 文件中添加配置:
<AddRazorSupportForMvc>true</AddRazorSupportForMvc>
转载请注明出处和作者,谢谢!
作者:JeffreySu / QQ:498977166
博客:http://szw.cnblogs.com/
Senparc官方教程《微信开发深度解析:微信公众号、小程序高效开发秘籍》,耗时2年精心打造的微信开发权威教程,点击这里,购买正版!