简体   繁体   English

VS2017 MSBuildWorkspace无法使用转换后的ASP.Net Core Web应用程序打开解决方案

[英]VS2017 MSBuildWorkspace fails opening solution with converted ASP.Net Core Web application

I've set up some solution sanity tests using the Microsoft.CodeAnalysis packages and everything went smooth util I installed VS2017 and coverted my ASP.Net Core Web application. 我已经使用Microsoft.CodeAnalysis软件包设置了一些解决方案健全性测试,一切顺利,我安装了VS2017并转换了我的ASP.Net Core Web应用程序。 Due to the csproj file simplification ( https://blogs.msdn.microsoft.com/dotnet/2016/12/12/updating-visual-studio-2017-rc-net-core-tooling-improvements/ ) it seems that the solution can't be opened anymore. 由于csproj文件简化( https://blogs.msdn.microsoft.com/dotnet/2016/12/12/updating-visual-studio-2017-rc-net-core-tooling-improvements/ ),似乎解决方案不能再打开了。 The code I use is the following: 我使用的代码如下:

var workspace = MSBuildWorkspace.Create();
var solution = workspace.OpenSolutionAsync(slnPath).Result;

and this is the exception I'm getting: 这是我得到的例外:

Microsoft.Build.Exceptions.InvalidProjectFileException
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 <Project> element. If the project has been authored in the old 1.0 or 1.2 format, please convert it to MSBuild 2003 format.
   at Microsoft.Build.Shared.ProjectErrorUtilities.ThrowInvalidProject(String errorSubCategoryResourceName, IElementLocation elementLocation, String resourceName, Object[] args)
   at Microsoft.Build.Construction.ProjectParser.Parse()
   at Microsoft.Build.Construction.ProjectParser.Parse(XmlDocumentWithLocation document, ProjectRootElement projectRootElement)
   at Microsoft.Build.Construction.ProjectRootElement.Create(XmlReader xmlReader, ProjectCollection projectCollection)
   at Microsoft.CodeAnalysis.MSBuild.ProjectFileLoader.<LoadProjectAsync>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.CodeAnalysis.MSBuild.ProjectFileLoader.<LoadProjectFileAsync>d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.CodeAnalysis.MSBuild.MSBuildProjectLoader.<LoadProjectAsync>d__23.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.CodeAnalysis.MSBuild.MSBuildProjectLoader.<GetOrLoadProjectAsync>d__22.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.CodeAnalysis.MSBuild.MSBuildProjectLoader.<LoadSolutionInfoAsync>d__18.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.CodeAnalysis.MSBuild.MSBuildWorkspace.<OpenSolutionAsync>d__18.MoveNext()

It seems to me that the new csproj structure is not fully supported. 在我看来,新的csproj结构并不完全支持。 A possible solution may be creating a separate solution without the converted project, but it will be really a workaround. 一个可能的解决方案可能是在没有转换项目的情况下创建单独的解决方案,但它确实是一种解决方法。 Any ideas? 有任何想法吗?

Edit: 编辑:

I've tried to follow the suggestion in the error message, namely adding the xmlns attribute like so: 我试图按照错误消息中的建议,即添加xmlns属性,如下所示:

<Project Sdk="Microsoft.NET.Sdk.Web" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <TargetFramework>net452</TargetFramework>
    <RuntimeIdentifier>win7-x86</RuntimeIdentifier>
    <GenerateDocumentationFile>true</GenerateDocumentationFile>
    <PreserveCompilationContext>true</PreserveCompilationContext>
    <AssemblyName>Arcmedia.Esl.WebApp.Api</AssemblyName>
    <OutputType>Exe</OutputType>
    <PackageId>Arcmedia.Esl.WebApp.Api</PackageId>
  </PropertyGroup>
  <ItemGroup>
    <None Include="App.config" />
    <Content Update="wwwroot;web.config">
      <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
    </Content>
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Hosting" Version="1.1.0" />
    <PackageReference Include="Microsoft.AspNetCore.Hosting.Abstractions" Version="1.1.0" />
    <PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="1.1.0" />
    <PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="1.1.0" />
  </ItemGroup>
  <ItemGroup Condition=" '$(TargetFramework)' == 'net452' ">
    <Reference Include="System" />
    <Reference Include="Microsoft.CSharp" />
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\xyz\abc.def.csproj" />
  </ItemGroup>
</Project>

but that didn't solve the problem, because right now I get another exception: 但这并没有解决问题,因为现在我得到另一个例外:

Microsoft.Build.Exceptions.InvalidProjectFileException
The attribute "Update" in element <Content> is unrecognized.
   at Microsoft.Build.Shared.ProjectErrorUtilities.ThrowInvalidProject(String errorSubCategoryResourceName, IElementLocation elementLocation, String resourceName, Object[] args)
   at Microsoft.Build.Internal.ProjectXmlUtilities.ThrowProjectInvalidAttribute(XmlAttributeWithLocation attribute)
   at Microsoft.Build.Internal.ProjectXmlUtilities.VerifyThrowProjectAttributes(XmlElementWithLocation element, String[] validAttributes)
   at Microsoft.Build.Construction.ProjectParser.ParseProjectItemElement(XmlElementWithLocation element, ProjectItemGroupElement parent)
   at Microsoft.Build.Construction.ProjectParser.ParseProjectItemGroupElement(XmlElementWithLocation element, ProjectElementContainer parent)
   at Microsoft.Build.Construction.ProjectParser.ParseProjectRootElementChildren(XmlElementWithLocation element)
   at Microsoft.Build.Construction.ProjectParser.Parse()
   at Microsoft.Build.Construction.ProjectParser.Parse(XmlDocumentWithLocation document, ProjectRootElement projectRootElement)
   at Microsoft.Build.Construction.ProjectRootElement.Create(XmlReader xmlReader, ProjectCollection projectCollection)
   at Microsoft.CodeAnalysis.MSBuild.ProjectFileLoader.<LoadProjectAsync>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.CodeAnalysis.MSBuild.ProjectFileLoader.<LoadProjectFileAsync>d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.CodeAnalysis.MSBuild.MSBuildProjectLoader.<LoadProjectAsync>d__23.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.CodeAnalysis.MSBuild.MSBuildProjectLoader.<GetOrLoadProjectAsync>d__22.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.CodeAnalysis.MSBuild.MSBuildProjectLoader.<LoadSolutionInfoAsync>d__18.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.CodeAnalysis.MSBuild.MSBuildWorkspace.<OpenSolutionAsync>d__18.MoveNext()

So, back to my original conclusion, it seems that the new simplified csproj file structure is not properly supported while trying to use Microsoft.CodeAnalysis.MSBuild.MSBuildWorkspace.OpenSolutionAsync 所以,回到我原来的结论,似乎在尝试使用Microsoft.CodeAnalysis.MSBuild.MSBuildWorkspace.OpenSolutionAsync时,没有正确支持新的简化csproj文件结构。

The problem is occurring because the project file is using a new schema format for VS2017 csproj, but msbuild is being run from an older install (possibly VS2015) on your machine. 问题出现是因为项目文件正在使用VS2017 csproj的新架构格式,但msbuild正在您的计算机上从较旧的安装(可能是VS2015)运行。 This happens because the Roslyn MSBuildWorkspace that you have is built against the prior version of MSBuild API that doesn't understand the new format and is using that version instead of the newer version on your machine. 发生这种情况是因为您拥有的Roslyn MSBuildWorkspace是针对以前版本的MSBuild API构建的,该版本不了解新格式并且在您的计算机上使用该版本而不是更新版本。 If you didn't have the older version on the machine MSBuildWorkspace would have failed immediately with a type load exception. 如果您在计算机上没有旧版本,则MSBuildWorkspace会立即因类型加载异常而失败。

MSBuildWorkspace has been update to the newer VS2017 version, but it is not yet on nuget. MSBuildWorkspace已经更新到较新的VS2017版本,但它还没有在nuget上。 You can get if from the Roslyn myget feed. 您可以从Roslyn myget Feed中获取。

Check out this github issue for more details: https://github.com/dotnet/roslyn/issues/16886 有关更多详细信息,请查看此github问题: https//github.com/dotnet/roslyn/issues/16886

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法在vs2017(.net Core)中运行WebAPI解决方案 - Unable to run webapi solution in vs2017(.net core) VS 2017 ASP.Net Core Web应用程序无法定位.Net Framework - VS 2017 ASP.Net Core Web Application cannot target .Net Framework 将asp.net核心React-Redux WebApp从VS2017迁移到Visual Studio Code? - Migrate asp.net core React-Redux WebApp from VS2017 to Visual Studio Code? .Net Core Project中vs2017缺少web.config - vs2017 missing web.config in .Net Core Project 在ASP.NET MVC 5项目中在VS2017中连接到MySQL - Connecting to MySQL in VS2017 in ASP.NET MVC 5 project VS 2017 .NET 4.6.2新的ASP.NET核心Web应用程序(.NET Framework)默认为x86平台 - VS 2017 .NET 4.6.2 new ASP.NET Core Web Application (.NET Framework) defaults to x86 platform Asp.Net Core SPA vs 分离解决方案(Asp.Net Core WebApi + Web app) - Asp.Net Core SPA vs separated solution (Asp.Net Core WebApi + Web app) 在VS2017 ASP.NET中找不到在哪里启用SSL - Can't find where to enable SSL in VS2017 ASP.NET VS2017中使用Crystal Reports错误&#39;Invalid Subreport Name&#39;的Asp.Net应用 - Asp.Net app in VS2017 using Crystal Reports error 'Invalid Subreport Name' Asp.net Crystal Reports对子报表的更改未在vs2017调试/发布模式下显示 - Asp.net Crystal Reports changes to child reports not showing in vs2017 debug/release mode
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM