internal static MsBuildProjectPrimitive GetProjectWithMsBuild( string localPath, string originalProjectName) { try { ProjectCollection.GlobalProjectCollection.UnloadAllProjects(); var project = new Project(localPath); var parser = new PathParser(); var projectName = parser.GetLastItemFromPath(localPath); var targetFrameworks = MsBuildPropertyStatics.GetTargetFrameworksIfApplicable(project); var relativePaths = MsBuildPropertyStatics.GetRelativeProjectReferencePaths(project); var defaultNamespace = MsBuildPropertyStatics.GetDefaultNamespace(project); var assemblyName = MsBuildPropertyStatics.GetAssemblyName(project); var originalProjectNameExpr = originalProjectName != null ? "<-" + originalProjectName : string.Empty; Console.WriteLine($"Found project {projectName} {originalProjectNameExpr}"); return(new MsBuildProjectPrimitive { Name = projectName, TargetFrameworks = targetFrameworks?.ToList(), DefaultNamespace = defaultNamespace, AssemblyName = assemblyName, RelativeProjectReferencePaths = relativePaths.ToList() }); } catch (Exception e) when (e is InvalidProjectFileException || e is InvalidOperationException || e is IOException) { return(new MsBuildProjectPrimitive { Failed = true, Error = e }); } }
internal static MsBuildSolutionPrimitive GetSolutionWithMsBuild( string localPath, string originalSolutionName) { try { ProjectCollection.GlobalProjectCollection.UnloadAllProjects(); var solution = SolutionFile.Parse(localPath); var parser = new PathParser(); var solutionName = parser.GetLastItemFromPath(localPath); var configurations = MsBuildPropertyStatics.GetConfigurations(solution); var relativePaths = MsBuildPropertyStatics.GetProjectRelativePaths(solution); var originalSolutionNameExpr = originalSolutionName != null ? "<-" + originalSolutionName : string.Empty; Console.WriteLine($"Found solution {solutionName} {originalSolutionNameExpr}"); return(new MsBuildSolutionPrimitive { Name = solutionName, Configurations = configurations, RelativeProjectPaths = relativePaths }); } catch (Exception e) when (e is InvalidProjectFileException || e is InvalidOperationException || e is IOException) { return(new MsBuildSolutionPrimitive { Error = e, Failed = true }); } }
internal static MsBuildPublishProfilePrimitive GetPublishProfileFromXmlFile( string localPath, string originalPublishProfileName) { try { var document = new XmlDocument(); document.Load(localPath); var namespaceValue = document.CreateLegacyMsBuildNamespace(); var publishUrl = document.GetSingleNodeInnerText("//ns:Project/ns:PropertyGroup/ns:publishUrl", namespaceValue); publishUrl = publishUrl.Replace("$(ProjectDir)", string.Empty); document = null; var parser = new PathParser(); var publishProfileName = parser.GetLastItemFromPath(localPath); var originalPublishProfileNameExpr = originalPublishProfileName != null ? "<-" + originalPublishProfileName : string.Empty; Console.WriteLine($"Found publish profile {publishProfileName} {originalPublishProfileNameExpr}"); return(new MsBuildPublishProfilePrimitive { Name = publishProfileName, PublishUrl = publishUrl }); } catch (Exception e) { return(new MsBuildPublishProfilePrimitive { Failed = true, Error = e }); } }
internal static MsBuildPublishProfilePrimitive GetPublicProfileWithMsBuild( string localPath, string originalPublishProfileName) { try { ProjectCollection.GlobalProjectCollection.UnloadAllProjects(); var publishProfile = new Project(localPath); var parser = new PathParser(); var publishProfileName = parser.GetLastItemFromPath(localPath); var publishUrl = MsBuildPropertyStatics.GetPublishUrl(publishProfile); var originalPublishProfileNameExpr = originalPublishProfileName != null ? "<-" + originalPublishProfileName : string.Empty; Console.WriteLine($"Found publish profile {publishProfileName} {originalPublishProfileNameExpr}"); return(new MsBuildPublishProfilePrimitive { Name = publishProfileName, PublishUrl = publishUrl }); } catch (Exception e) when (e is InvalidProjectFileException || e is InvalidOperationException || e is IOException) { return(new MsBuildPublishProfilePrimitive { Failed = true, Error = e }); } }
internal static MsBuildProjectPrimitive GetProjectFromXmlFile( string localPath, string originalProjectName) { try { var document = new XmlDocument(); document.Load(localPath); var namespaceValue = document.CreateLegacyMsBuildNamespace(); string defaultNamespace = null, assemblyName; List <string> targetFrameworks = null, relativePaths; bool isNetCoreProject; if (namespaceValue.NsManager != null) { // legacy .NET Framework defaultNamespace = document.GetSingleNodeInnerText("//ns:Project/ns:PropertyGroup/ns:RootNamespace", namespaceValue); assemblyName = document.GetSingleNodeInnerText("//ns:Project/ns:PropertyGroup/ns:AssemblyName", namespaceValue); relativePaths = document.GetNodesPropertyValue("//ns:Project/ns:ItemGroup/ns:ProjectReference", "Include", namespaceValue)?.ToList(); isNetCoreProject = false; } else { // .NET Core and newer assemblyName = document.GetSingleNodeInnerText("//Project/PropertyGroup/AssemblyName", namespaceValue); targetFrameworks = document .GetSingleNodeInnerText("//Project/PropertyGroup/TargetFramework", namespaceValue)?.Split(';') ?.ToList(); relativePaths = document .GetNodesPropertyValue("//Project/ItemGroup/ProjectReference", "Include", namespaceValue) ?.ToList(); isNetCoreProject = true; } document = null; var parser = new PathParser(); var projectName = parser.GetLastItemFromPath(localPath); var originalProjectNameExpr = originalProjectName != null ? "<-" + originalProjectName : string.Empty; Console.WriteLine($"Found project {projectName} {originalProjectNameExpr}"); return(new MsBuildProjectPrimitive { Name = projectName, TargetFrameworks = targetFrameworks, DefaultNamespace = defaultNamespace, AssemblyName = assemblyName, RelativeProjectReferencePaths = relativePaths, IsNetCoreProject = isNetCoreProject }); } catch (Exception e) { return(new MsBuildProjectPrimitive { Failed = true, Error = e }); } }