在Microsoft.WebTools.Aspire.targets中的错误:'<' 是一个无效的值起始字符。行号:2 | 行内字节位置:0
在我构建项目时,Visual Studio 2026(最新版)会出现这个错误,但如果我运行解决方案,仍然可以工作。此外,只有这两个出现问题的项目在将鼠标悬停在代码“IEnumerable”上时会有额外的问题——编辑器不会显示颜色高亮,也不会弹出描述的提示框。
我的Windows 11电脑重新格式化并重新安装后,问题大约持续了一周就解决了。我不认为这是针对某个项目的问题,因为这个项目有3 名开发者在用,而我是唯一在构建该项目时遇到此问题的人。
我听说这可能是因为返回的HTML页面(如403或 404页面)所致,但如果我点击错误信息,可以清楚地看到返回的是XML。
我还使用 https://www.w3schools.com/xml/xml_validator.asp 对该XML进行验证,结果显示为有效。
GitHub Copilot也表示
“错误指出有某些东西试图把这个XML文件解析为JSON。该文件本身是有效的MSBuild XML语法。”
我没有任何自定义构建流程,据我所知,项目中也没有引用“Aspire”,所以它为何会对此进行任何操作尚不可知。
高亮显示的XML区块是
<GenerateCombinedAppSettingsSchema
AppSettingJsonSchemaFilePath="$(AppSettingJsonSchemaLoadFilePath)"
ComponentJsonSchemaCombinedFilePath="$(JsonSchemaCombinedFilePath)"
AppSettingsJsonSchemaCombinedFilePath="$(AppSettingsJsonSchemaCombinedFilePath)">
</GenerateCombinedAppSettingsSchema>
下面是C:\Program Files\Microsoft Visual Studio\18\Community\MSBuild\Microsoft\VisualStudio\WebTools.Aspire\Microsoft.WebTools.Aspire.targets的内容
<?xml version="1.0" encoding="utf-8"?>
<!--
***********************************************************************************************
Microsoft.WebTools.Aspire.targets
WARNING: DO NOT MODIFY this file unless you are knowledgeable about MSBuild and have
created a backup copy. Incorrect changes to this file will make it
impossible to load or build your projects from the command-line or the IDE.
Copyright (C) Microsoft Corporation. All rights reserved.
***********************************************************************************************
-->
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask
TaskName="Microsoft.WebTools.Aspire.MSBuild.GenerateCombinedComponentSchema"
AssemblyFile="Microsoft.WebTools.Aspire.MSBuild.dll" />
<UsingTask
TaskName="Microsoft.WebTools.Aspire.MSBuild.GenerateCombinedAppSettingsSchema"
AssemblyFile="Microsoft.WebTools.Aspire.MSBuild.dll" />
<PropertyGroup>
<JsonSchemaCombinedFilePath>$(IntermediateOutputPath)\CombinedComponentSchema.json</JsonSchemaCombinedFilePath>
<JsonSchemaCombinedFilePath>$([MSBuild]::NormalizePath($(MSBuildProjectDirectory), $(JsonSchemaCombinedFilePath)))</JsonSchemaCombinedFilePath>
<AppSettingsJsonSchemaCombinedFilePath>$(IntermediateOutputPath)\AppSettingsSchema.json</AppSettingsJsonSchemaCombinedFilePath>
<AppSettingsJsonSchemaCombinedFilePath>$([MSBuild]::NormalizePath($(MSBuildProjectDirectory), $(AppSettingsJsonSchemaCombinedFilePath)))</AppSettingsJsonSchemaCombinedFilePath>
<SchemaGenIncrementalBuildInputs>@(JsonSchemaSegment);$(ProjectAssetsFile)</SchemaGenIncrementalBuildInputs>
</PropertyGroup>
<Target Name="GenerateCombinedComponentSchemaTarget"
Condition=" '@(JsonSchemaSegment)' != '' "
Inputs="$(SchemaGenIncrementalBuildInputs)"
Outputs="$(JsonSchemaCombinedFilePath)">
<GenerateCombinedComponentSchema
JsonSchemaSegmentFiles="@(JsonSchemaSegment)"
JsonSchemaCombinedFilePath="$(JsonSchemaCombinedFilePath)">
</GenerateCombinedComponentSchema>
</Target>
<Target Name="GenerateCombinedAppSettingsSchemaTarget"
DependsOnTargets="GenerateCombinedComponentSchemaTarget"
Condition=" '@(JsonSchemaSegment)' != '' "
BeforeTargets="CompileDesignTime"
Inputs="$(SchemaGenIncrementalBuildInputs);$(JsonSchemaCombinedFilePath)"
Outputs="$(AppSettingsJsonSchemaCombinedFilePath)">
<GenerateCombinedAppSettingsSchema
AppSettingJsonSchemaFilePath="$(AppSettingJsonSchemaLoadFilePath)"
ComponentJsonSchemaCombinedFilePath="$(JsonSchemaCombinedFilePath)"
AppSettingsJsonSchemaCombinedFilePath="$(AppSettingsJsonSchemaCombinedFilePath)">
</GenerateCombinedAppSettingsSchema>
<Message Text="Generating appsettingsschema" />
</Target>
<Target Name="CleanupCombinedAppSettingsSchemaTarget"
Condition=" '@(JsonSchemaSegment)' == '' "
BeforeTargets="CompileDesignTime">
<Delete Files="$(AppSettingsJsonSchemaCombinedFilePath)" />
<Message Text="Deleting appsettingsschema" />
</Target>
</Project>
看起来使用NuGet包 Azure.Identity,版本1.20.0或更高版本,会导致这个错误,但我不知道为什么。
解决方案
其实是Azure.Core 1.52.0及以上版本的传递性依赖导致的问题。
Bug已记录
站内所有文章版权归属LeftHeroAI导航站,无授权禁止任何主体转载、抄袭、复制内容,亦不得私自架设镜像站点。一经侵权,本站将通过法律途径追责。