dotnet-installer/src/dotnet/ProjectRootElementExtensions.cs
Peter Huene e30fe29aab
Fix project type GUIDs when adding projects to solution files.
This commit ensures the correct property (`ProjectTypeGuids`) is respected when
adding a project to a solution file.

Additionally, we now error if a project type GUID cannot be determined rather
than incorrectly mapping to the C# project type.

Enabled previously disabled tests that were waiting on upstream changes from
MSBuild and F#.

Fixes #5131.
Fixes #7742.
2018-03-22 21:32:39 -07:00

23 lines
837 B
C#

// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Build.Construction;
namespace Microsoft.DotNet.Tools.Common
{
public static class ProjectRootElementExtensions
{
public static string GetProjectTypeGuid(this ProjectRootElement rootElement)
{
return rootElement
.Properties
.FirstOrDefault(p => string.Equals(p.Name, "ProjectTypeGuids", StringComparison.OrdinalIgnoreCase))
?.Value
.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries)
.LastOrDefault(g => !string.IsNullOrWhiteSpace(g));
}
}
}