asp.net-mvc 项目的默认 XML 命名空间必须是 MSBuild XML 命名空间

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42509313/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-07 23:36:23  来源:igfitidea点击:

The default XML namespace of the project must be the MSBuild XML namespace

asp.net-mvcasp.net-corevisual-studio-2015msbuild.net-core

提问by David Pine

I cloned the ASP.NET Core SignalR Repolocally, and try opening the solution from within the following environment.

我在本地克隆了ASP.NET Core SignalR Repo,并尝试从以下环境中打开解决方案。

IDE

集成开发环境

Microsoft Visual Studio Enterprise 2015
Version 14.0.25431.01 Update 3
Microsoft .NET Framework
Version 4.6.01055

DOT NET CLI

DOT NET CLI

λ dotnet --info
.NET Command Line Tools (1.0.0-preview2-1-003177)

Product Information:
 Version:            1.0.0-preview2-1-003177
 Commit SHA-1 hash:  a2df9c2576

Runtime Environment:
 OS Name:     Windows
 OS Version:  6.1.7601
 OS Platform: Windows
 RID:         win7-x64

I end up seeing a lot of these kinds of error messages:

我最终看到了很多此类错误消息:

..\Repos\SignalR\src\Microsoft.AspNetCore.SignalR\Microsoft.AspNetCore.SignalR.csproj: error : The default XML namespace of the project must be the MSBuild XML namespace. If the project is authored in the MSBuild 2003 format, please add xmlns="http://schemas.microsoft.com/developer/msbuild/2003"to the element. If the project has been authored in the old 1.0 or 1.2 format, please convert it to MSBuild 2003 format. ..\Repos\SignalR\src\Microsoft.AspNetCore.SignalR\Microsoft.AspNetCore.SignalR.csproj

..\Repos\SignalR\src\Microsoft.AspNetCore.SignalR\Microsoft.AspNetCore.SignalR.csproj: 错误 : 项目的默认 XML 命名空间必须是 MSBuild XML 命名空间。如果项目是以 MSBuild 2003 格式创作的,请添加 xmlns="http://schemas.microsoft.com/developer/msbuild/2003"到元素中。如果项目是用旧的 1.0 或 1.2 格式创作的,请将其转换为 MSBuild 2003 格式。 ..\Repos\SignalR\src\Microsoft.AspNetCore.SignalR\Microsoft.AspNetCore.SignalR.csproj

I want to know how to fix this the correct way.

我想知道如何以正确的方式解决这个问题。

回答by DavidG

The projects you are trying to open are in the new .NET Core csproj format. This means you need to use Visual Studio 2017 which supports this new format.

您尝试打开的项目采用新的 .NET Core csproj 格式。这意味着您需要使用支持这种新格式的 Visual Studio 2017。

For a little bit of history, initially .NET Core used project.jsoninstead of *.csproj. However, after some considerable internal deliberation at Microsoft, they decided to go back to csprojbut with a much cleaner and updated format. However, this new format is only supported in VS2017.

对于一点历史,最初使用 .NET Coreproject.json而不是*.csproj. 但是,经过 Microsoft 的一些相当大的内部审议后,他们决定返回到csproj一个更干净和更新的格式。但是,这种新格式仅在 VS2017 中受支持。

If you want to open the projects but don't want to wait until March 7thfor the official VS2017 release, you could use Visual Studio Code instead.

如果您想打开项目但又不想等到 3 月 7正式发布 VS2017,则可以使用 Visual Studio Code。

回答by Jersey_Guy

I ran into this issue while opening the Service Fabric GettingStartedApplicationin Visual Studio 2015. The original solution was built on .NET Core in VS 2017 and I got the same error when opening in 2015.

我在 Visual Studio 2015 中打开 Service Fabric GettingStartedApplication时遇到了这个问题。原始解决方案是基于 VS 2017 中的 .NET Core 构建的,我在 2015 年打开时遇到了同样的错误。

Here are the steps I followed to resolve the issue.

以下是我为解决此问题而遵循的步骤。

  • Right click on (load Failed) project and edit in visual studio.
  • Saw the following line in the Project tag: <Project Sdk="Microsoft.NET.Sdk.Web" >

  • Followed the instruction shown in the error message to add xmlns="http://schemas.microsoft.com/developer/msbuild/2003"to this tag

  • 右键单击(加载失败)项目并在 Visual Studio 中进行编辑。
  • 在 Project 标签中看到以下行: <Project Sdk="Microsoft.NET.Sdk.Web" >

  • 按照错误消息中显示的说明添加xmlns="http://schemas.microsoft.com/developer/msbuild/2003"到此标签

It should now look like:

它现在应该是这样的:

<Project Sdk="Microsoft.NET.Sdk.Web" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  • Reloading the project gave me the next error (yours may be different based on what is included in your project)
  • 重新加载项目给了我下一个错误(根据项目中包含的内容,您的错误可能会有所不同)

"Update" element <None>is unrecognized

“更新”元素 <None>无法识别

  • Saw that None element had an update attribute as below:

    <None Update="wwwroot\**\*;Views\**\*;Areas\**\Views">
      <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
    </None>
    
  • Commented that out as below.

    <!--<None Update="wwwroot\**\*;Views\**\*;Areas\**\Views">
      <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
    </None>-->
    
  • Onto the next error: Version in Package Reference is unrecognized Version in element <PackageReference>is unrecognized

  • Saw that Version is there in csproj xml as below (Additional PackageReference lines removed for brevity)

  • Stripped the Version attribute

    <PackageReference Include="Microsoft.AspNetCore.Diagnostics" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc" />
    
  • I now get the following: VS Auto Upgrade

  • 看到 None 元素具有如下更新属性:

    <None Update="wwwroot\**\*;Views\**\*;Areas\**\Views">
      <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
    </None>
    
  • 评论如下。

    <!--<None Update="wwwroot\**\*;Views\**\*;Areas\**\Views">
      <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
    </None>-->
    
  • 下一个错误:无法识别包参考中的版本 元素 <PackageReference>中的版本无法识别

  • 看到版本在 csproj xml 中,如下所示(为简洁起见,已删除其他 PackageReference 行)

  • 剥离了版本属性

    <PackageReference Include="Microsoft.AspNetCore.Diagnostics" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc" />
    
  • 我现在得到以下信息: VS 自动升级

Bingo!The visual Studio One-way upgrade kicked in! Let VS do the magic!

答对了!Visual Studio 单向升级开始了!让VS变魔术!

  • The Project loaded but with reference lib errors. enter image description here

  • Fixed the reference lib errors individually, by removing and replacing in NuGet to get the project working!

  • 项目已加载但有参考库错误。 在此处输入图片说明

  • 通过在 NuGet 中删除和替换来使项目正常工作,单独修复了参考库错误!

Hope this helps another code traveler :-D

希望这可以帮助另一个代码旅行者:-D

回答by Nikita G.

@DavidG's answer is correct, but I would like to add that if you're building from the command line, the equivalent solution is to make sure that you're using the appropriate version of msbuild(in this particular case, it needs to be version 15).

@DavidG 的答案是正确的,但我想补充一点,如果您是从命令行构建的,则等效的解决方案是确保您使用的是适当的版本msbuild(在这种特殊情况下,它需要是版本15)。

Run msbuild /?to see which version you're using or where msbuildto check which location the environment takes the executable from and update (or point to the right location of) the tools if necessary.

运行msbuild /?以查看您使用的是哪个版本或where msbuild检查环境从哪个位置获取可执行文件并在必要时更新(或指向正确的位置)工具。

Download the latest MSBuild tool from here.

这里下载最新的 MSBuild 工具。

回答by Scotty.NET

If getting this error trying to build .Net Core 2.0 app on VSTS then ensure your build definition is using the Hosted VS2017Agent queue.

如果尝试在 VSTS 上构建 .Net Core 2.0 应用程序时遇到此错误,请确保您的构建定义正在使用Hosted VS2017代理队列。

回答by you_rule

I was getting the same messages while I was running just msbuild from powershell.

当我从 powershell 运行 msbuild 时,我收到了相同的消息。

dotnet msbuild "./project.csproj"worked for me.

dotnet msbuild "./project.csproj"对我来说有效。

回答by Mohammad Ahmad Abdullah

if the project is not a big ,

如果项目不大

1- change the name of folder project

1-更改文件夹项目的名称

2- make a new project with the same project (before renaming)

2-使用相同的项目创建一个新项目(重命名之前)

3- add existing files from the old project to the new project (totally same , same folders , same names , ...)

3-将旧项目中的现有文件添加到新项目中(完全相同,相同的文件夹,相同的名称,...)

4- open the the new project file (as xml ) and the old project

4-打开新项目文件(作为 xml )和旧项目

5- copy the new project file (xml content ) and paste it in the old project file

5-复制新项目文件(xml内容)并粘贴到旧项目文件中

6- delete the old project

6-删除旧项目

7- rename the old folder project to old name

7-将旧文件夹项目重命名为旧名称