DevOp构建错误关于Blazor项目的命名空间/引用

huangapple go评论79阅读模式
英文:

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:

DevOp构建错误关于Blazor项目的命名空间/引用

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:

DevOp构建错误关于Blazor项目的命名空间/引用

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 :
DevOp构建错误关于Blazor项目的命名空间/引用

英文:

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.

Here is the change that did the trick :
DevOp构建错误关于Blazor项目的命名空间/引用

答案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.

huangapple
  • 本文由 发表于 2023年5月17日 09:23:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/76268005.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定