英文:
DevOp build error on blazor project namespace/reference
问题
I have a blazor solution and been building it on DevOps for like 6 months, no problem. And suddenly today, DevOps fails to build the solutions. The specific errors are:
I have no idea what these errors are referring to as these components/namespaces are all correct. Solution builds locally without any issues.
The only thing I saw that could be a problem is this:
CSC : warning CS9057: The analyzer assembly 'F:\agent_work_tool\dotnet\sdk\7.0.302\Sdks\Microsoft.NET.Sdk.Razor\source-generators\Microsoft.NET.Sdk.Razor.SourceGenerators.dll' references version '4.6.0.0' of the compiler, which is newer than the currently running version '4.4.0.0'. [F:\agent_work\14\s\UIComponent\UIComponent.csproj]
I researched this and could not find anything. Is this error the root cause of the build error?
Does anyone run into such issues? I verified the build server has both .net 6 and .net 7 SDK installed.
英文:
I have a blazor solution and been building it on DevOps for like 6 months, no problem. And suddenly today, DevOp fails to build the solutions. The specific errors are:
I have no idea what these errors are referring to as these components/namespaces are all correct. Solution builds locally without any issues.
The only thing I saw that could be a problem is this:
CSC : warning CS9057: The analyzer assembly 'F:\agent\_work\_tool\dotnet\sdk.0.302\Sdks\Microsoft.NET.Sdk.Razor\source-generators\Microsoft.NET.Sdk.Razor.SourceGenerators.dll' references version '4.6.0.0' of the compiler, which is newer than the currently running version '4.4.0.0'. [F:\agent\_work\s\UIComponent\UIComponent.csproj]
I researched this and could not find anything. Is this error the root cause of the build error?
Does anyone run into such issues? I verified the build server has both .net 6 and .net 7 SDK installed.
答案1
得分: 1
我更新到最新的VS版本后,遇到了几乎相同的问题。
.NET 7.0.302(MSBuild版本17.6.1+8ffc3fe3d)
错误 CS0400:全局命名空间中找不到类型或命名空间名称'...'(是否缺少程序集引用?)
错误 CS1662:无法将lambda表达式转换为预期的委托类型,因为块中的某些返回类型不能隐式转换为委托返回类型
解决此问题的方法是对某些 Blazor 组件参数使用完整的命名空间:
public Icons.Icon.IconStyle Style { get; set; }
=>
public MyNamespace.Blazor.Components.Icons.Icon.IconStyle Style { get; set; }
尽管VS可以解析正确的命名空间,但msbuild 无法解析。
英文:
I had almost the same problem after updating to the latest VS version.
.NET 7.0.302 (MSBuild version 17.6.1+8ffc3fe3d)
Error CS0400: The type or namespace name '...' could not be found in the global namespace (are you missing an assembly reference?)
Error CS1662: Cannot convert lambda expression to intended delegate type because some of the return types in the block are not implicitly convertible to the delegate return type
The solution for this problem was to use the full namespace for some Blazor component-parameters:
public Icons.Icon.IconStyle Style { get; set; }
=>
public MyNamespace.Blazor.Components.Icons.Icon.IconStyle Style { get; set;}
Althouth VS could resolve the correct namespace, msbuild couldn't.
答案2
得分: 1
I was having similar issues with .Net 7 Blazor WASM project. Everything built fine locally using VS 2022 (17.5.3 and even 17.6.0).
For some reason DevOps decided it couldn't build the client-side portion of our project, complaining about a single namespace issue and that it could not find a suitable method to override where our components were overriding the Blazor lifecycle methods (OnInitializedAsync, OnParametersSet, etc)
Initially I worked around the namespace issue by splitting out the @code{ } part of the Razor file (which was empty anyway) into its own .cs file so that the namespace declaration was explicit.
That worked but may have not been necessary.
The bigger part of the solution was to specify the VS version (instead of the sdk version) in our VS Build task in the yaml build file. I cannot explain exactly why that worked though. Maybe someone can add comment if they understand why.
Here is the change that did the trick :
英文:
I was having similar issues with .Net 7 Blazor WASM project. Everything built fine locally using VS 2022 (17.5.3 and even 17.6.0).
For some reason DevOps decided it couldn't build the client-side portion of our project, complaining about a single namespace issue and that it could not find a suitable method to override where our components were overriding the Blazor lifecycle methods (OnInitializedAsync, OnParametersSet, etc)
Initially I worked around the namespace issue by splitting out the @code{ } part of the Razor file (which was empty anyway) into it's own .cs file so that the namespace declaration was explicit.
That worked but may have not been necessary.
The bigger part of the solution was to specify the VS version (instead of the sdk version) in our VS Build task in the yaml build file. I cannot explain exactly why that worked though. Maybe someone can add comment if they understand why.
答案3
得分: 0
I've added a NuGet package called Microsoft.Net.Compilers.Toolset, version 4.6.0 to the UIComponent project, that fixed the build issue. Still not sure why I need to do this and how it worked before.
英文:
I've added a NuGet package called Microsoft.Net.Compilers.Toolset, version 4.6.0 to the UIComponent project, that fixed the build issue. Still not sure why I need to do this and how it worked before.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论