2017-02-09 1 views
1

J'ai mis en place des tests de cohérence de la solution en utilisant les packages Microsoft.CodeAnalysis et tout s'est bien déroulé. J'ai installé VS2017 et j'ai converti mon application ASP.Net Core Web. En raison de la simplification du fichier csproj (https://blogs.msdn.microsoft.com/dotnet/2016/12/12/updating-visual-studio-2017-rc-net-core-tooling-improvements/), il semble que la solution ne puisse plus être ouverte. Le code que j'utilise est le suivant:VS2017 MSBuildWorkspace ne parvient pas à ouvrir la solution avec l'application Web convertie ASP.Net Core

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

ce qui est l'exception que je reçois:

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() 

Il me semble que la nouvelle structure de csproj n'est pas complètement pris en charge. Une solution possible peut être de créer une solution séparée sans le projet converti, mais ce sera vraiment une solution de contournement. Des idées?

Edit:

J'ai essayé de suivre la suggestion dans le message d'erreur, à savoir ajouter l'attribut xmlns comme ceci:

<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> 

mais cela n'a pas résolu le problème, parce qu'en ce moment Je reçois une autre 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() 

Revenons donc à ma conclusion initiale, il semble que la nouvelle structure de fichier csproj simplifiée n'est pas correctement pris en charge, tout en essayant d'utiliser Microsoft.CodeAnalysis.MSBuild.MSBuildWorkspace.OpenSolutionAsync

+0

L'erreur est extrêmement claire et vous donne la solution: 'Si le projet est écrit au format MSBuild 2003, s'il vous plaît ajouter xmlns =" ​​http: // schémas .microsoft.com/developer/msbuild/2003 "à l'élément ." – Gusman

+0

@Gusman Si vous suivez le lien que j'ai fourni, vous verrez les changements que le fichier csproj recevra. C'est probablement dû au fait que ce type de projet sera également affiché différemment dans VS2017 (et de plus ne s'ouvrira pas dans la version précédente de VS, au moins en ce moment). –

+0

Cela semble être un bug: [link] (https://github.com/dotnet/roslyn/issues/16886) – PhatBuck

Répondre

1

Le problème se produit parce que le fichier de projet utilise un nouveau format de schéma pour VS2017 csproj, mais msbuild est exécuté à partir d'une ancienne installation (éventuellement VS2015) sur votre machine. Cela se produit parce que MSBuildWorkspace Roslyn que vous avez est construit par rapport à la version antérieure de l'API MSBuild qui ne comprend pas le nouveau format et utilise cette version au lieu de la version plus récente sur votre ordinateur. Si vous n'aviez pas l'ancienne version sur la machine, MSBuildWorkspace aurait immédiatement échoué avec une exception de chargement de type.

MSBuildWorkspace a été mis à jour vers la version la plus récente de VS2017, mais il n'est pas encore sur nuget. Vous pouvez obtenir à partir du flux de Roslyn myget.

Vérifiez cette question github pour plus de détails: https://github.com/dotnet/roslyn/issues/16886