3F / MvsSln

🧩 Customizable VisualStudio .sln parser with project support (.vcxproj, .csproj., …). Pluggable lightweight r/w handlers at runtime, and more …
MIT License
140 stars 27 forks source link

Unable to load Xamarin Project... #4

Open drarsalan opened 6 years ago

drarsalan commented 6 years ago

I am trying to load a solution which has xamarin project. I get the following exception.

Microsoft.Build.Exceptions.InvalidProjectFileException : The attribute "Version" in element <PackageReference> is unrecognized.  MyProject.Android.csproj
   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..ctor(String path, ProjectRootElementCache projectRootElementCache, BuildEventContext buildEventContext)
   at Microsoft.Build.Construction.ProjectRootElement.CreateProjectFromPath(String projectFile, IDictionary`2 globalProperties, String toolsVersion, ILoggingService loggingService, ProjectRootElementCache projectRootElementCache, BuildEventContext buildEventContext)
   at Microsoft.Build.Construction.ProjectRootElement.<>c__DisplayClass169_0.<OpenProjectOrSolution>b__0(String path, ProjectRootElementCache cache)
   at Microsoft.Build.Evaluation.ProjectRootElementCache.Get(String projectFile, OpenProjectRootElement openProjectRootElement, Boolean isExplicitlyLoaded)
   at Microsoft.Build.Construction.ProjectRootElement.OpenProjectOrSolution(String fullPath, IDictionary`2 globalProperties, String toolsVersion, ILoggingService loggingService, ProjectRootElementCache projectRootElementCache, BuildEventContext buildEventContext, Boolean isExplicitlyLoaded)
   at Microsoft.Build.Evaluation.Project..ctor(String projectFile, IDictionary`2 globalProperties, String toolsVersion, String subToolsetVersion, ProjectCollection projectCollection, ProjectLoadSettings loadSettings)
   at Microsoft.Build.Evaluation.Project..ctor(String projectFile, IDictionary`2 globalProperties, String toolsVersion, ProjectCollection projectCollection)
   at net.r_eg.MvsSln.Core.IsolatedEnv.Load(String path, IDictionary`2 properties) in D:\My Documents\Projects\MvsSln\MvsSln\Core\IsolatedEnv.cs:line 335
   at net.r_eg.MvsSln.Core.IsolatedEnv.Load(ProjectItem pItem, IDictionary`2 properties) in D:\My Documents\Projects\MvsSln\MvsSln\Core\IsolatedEnv.cs:line 323
   at net.r_eg.MvsSln.Core.IsolatedEnv.GetOrLoadProject(ProjectItem pItem, IDictionary`2 properties) in D:\My Documents\Projects\MvsSln\MvsSln\Core\IsolatedEnv.cs:line 209
   at net.r_eg.MvsSln.Core.IsolatedEnv.GetOrLoadProject(ProjectItem pItem, IConfPlatform cfg) in D:\My Documents\Projects\MvsSln\MvsSln\Core\IsolatedEnv.cs:line 170
   at net.r_eg.MvsSln.Core.IsolatedEnv.Load(IEnumerable`1 pItems) in D:\My Documents\Projects\MvsSln\MvsSln\Core\IsolatedEnv.cs:line 312
   at net.r_eg.MvsSln.Core.IsolatedEnv.LoadProjects(IEnumerable`1 pItems) in D:\My Documents\Projects\MvsSln\MvsSln\Core\IsolatedEnv.cs:line 266
   at net.r_eg.MvsSln.Core.SlnParser.Parse(StreamReader reader, SlnItems type) in D:\My Documents\Projects\MvsSln\MvsSln\Core\SlnParser.cs:line 151
   at net.r_eg.MvsSln.Core.SlnParser.Parse(String sln, SlnItems type) in D:\My Documents\Projects\MvsSln\MvsSln\Core\SlnParser.cs:line 103
   at net.r_eg.MvsSln.Sln..ctor(String file, SlnItems type) in D:\My Documents\Projects\MvsSln\MvsSln\Sln.cs:line 54

The project file has the following information.

  <ItemGroup>
    <PackageReference Include="Xamarin.Forms" Version="2.5.0.122203" />
    <PackageReference Include="Xamarin.Android.Support.Design" Version="25.4.0.2" />
    <PackageReference Include="Xamarin.Android.Support.v7.AppCompat" Version="25.4.0.2" />
    <PackageReference Include="Xamarin.Android.Support.v4" Version="25.4.0.2" />
    <PackageReference Include="Xamarin.Android.Support.v7.CardView" Version="25.4.0.2" />
    <PackageReference Include="Xamarin.Android.Support.v7.MediaRouter" Version="25.4.0.2" />
    <PackageReference Include="Microsoft.Azure.Mobile.Client" Version="4.0.1" />
    <PackageReference Include="Microsoft.Azure.Mobile.Client.SQLiteStore" Version="4.0.1" />
  </ItemGroup>
3F commented 6 years ago

Thanks for the report, @drarsalan

The attribute "Version" in element is unrecognized.

More like because of unrelated schema.

Can you also attach this project file (.csproj etc) ? Seems problem again with backward compatibility exactly in MS internal logic as for #2

Temporarily, you can try to override IsolatedEnv.Load with own logic

https://github.com/3F/MvsSln/blob/a84f0f246aaf571ce6f44f151369472711b2a635/MvsSln/Core/IsolatedEnv.cs#L333

Like we use this also in DllExport project to avoid some related problems:

3F commented 6 years ago

@drarsalan https://github.com/3F/MvsSln/issues/5#issuecomment-410464661 solves problem via other version of Microsoft.Build.dll. Check this out.

(.netfx 4.6+ for today)