From bf7c30e69c367341e564736aae1389b19cd081c8 Mon Sep 17 00:00:00 2001 From: Charles Betros Date: Tue, 11 Apr 2017 11:25:24 -0500 Subject: [PATCH] Fix some template issues and modified mpf a bit. --- .../Cosmos/CosmosProject.Cosmos | 5 +- .../CSharpProject.csproj | 2 + .../CSharpProject.csproj | 2 + source/Cosmos.VS.Wizards/CosmosProject.Cosmos | 5 +- source/MPF/12.0/AssemblyReferenceNode.cs | 73 ++++----- source/MPF/12.0/ConfigProvider.cs | 5 + source/MPF/12.0/IDEBuildLogger.cs | 10 +- source/MPF/12.0/ProjectReferenceNode.cs | 146 +++++++++++------- 8 files changed, 146 insertions(+), 102 deletions(-) diff --git a/source/Cosmos.VS.ProjectSystem/ProjectTemplates/Cosmos/CosmosProject.Cosmos b/source/Cosmos.VS.ProjectSystem/ProjectTemplates/Cosmos/CosmosProject.Cosmos index df7d7a982..d57604ce8 100644 --- a/source/Cosmos.VS.ProjectSystem/ProjectTemplates/Cosmos/CosmosProject.Cosmos +++ b/source/Cosmos.VS.ProjectSystem/ProjectTemplates/Cosmos/CosmosProject.Cosmos @@ -25,7 +25,10 @@ Pipe: Cosmos\Serial - + + $KernelProjectName$ + $KernelProjectGuid$ + diff --git a/source/Cosmos.VS.ProjectSystem/ProjectTemplates/CosmosKernel (CSharp)/CSharpProject.csproj b/source/Cosmos.VS.ProjectSystem/ProjectTemplates/CosmosKernel (CSharp)/CSharpProject.csproj index d2cfda956..eca863b06 100644 --- a/source/Cosmos.VS.ProjectSystem/ProjectTemplates/CosmosKernel (CSharp)/CSharpProject.csproj +++ b/source/Cosmos.VS.ProjectSystem/ProjectTemplates/CosmosKernel (CSharp)/CSharpProject.csproj @@ -1,6 +1,8 @@  + $KernelProjectName$3 + $KernelProjectGuid$ Library diff --git a/source/Cosmos.VS.ProjectSystem/ProjectTemplates/CosmosProject (CSharp)/CSharpProject.csproj b/source/Cosmos.VS.ProjectSystem/ProjectTemplates/CosmosProject (CSharp)/CSharpProject.csproj index d1ce46f7a..5728c5457 100644 --- a/source/Cosmos.VS.ProjectSystem/ProjectTemplates/CosmosProject (CSharp)/CSharpProject.csproj +++ b/source/Cosmos.VS.ProjectSystem/ProjectTemplates/CosmosProject (CSharp)/CSharpProject.csproj @@ -1,6 +1,8 @@  + $KernelProjectName$ + $KernelProjectGuid$ Library diff --git a/source/Cosmos.VS.Wizards/CosmosProject.Cosmos b/source/Cosmos.VS.Wizards/CosmosProject.Cosmos index 39d2e46ee..a1259d55f 100644 --- a/source/Cosmos.VS.Wizards/CosmosProject.Cosmos +++ b/source/Cosmos.VS.Wizards/CosmosProject.Cosmos @@ -25,7 +25,10 @@ Pipe: Cosmos\Serial - + + $KernelProjectName$ + $KernelProjectGuid$ + diff --git a/source/MPF/12.0/AssemblyReferenceNode.cs b/source/MPF/12.0/AssemblyReferenceNode.cs index ba6c7d3bc..52e0d796f 100644 --- a/source/MPF/12.0/AssemblyReferenceNode.cs +++ b/source/MPF/12.0/AssemblyReferenceNode.cs @@ -60,6 +60,7 @@ using MSBuild = Microsoft.Build.Evaluation; using MSBuildExecution = Microsoft.Build.Execution; using Microsoft.Build.Evaluation; using Microsoft.Build.Framework; +using Microsoft.Build.Execution; namespace Microsoft.VisualStudio.Project { @@ -378,71 +379,52 @@ namespace Microsoft.VisualStudio.Project private void SetHintPathAndPrivateValue() { + // Private means local copy; we want to know if it is already set to not override the default + string privateValue = this.ItemNode.GetMetadata(ProjectFileConstants.Private); + + // Get the list of items which require HintPath + ICollection references = this.ProjectMgr.CurrentConfig.GetItems(MsBuildGeneratedItemType.ReferenceCopyLocalPaths); + // Remove the HintPath, we will re-add it below if it is needed if(!String.IsNullOrEmpty(this.assemblyPath)) { this.ItemNode.SetMetadata(ProjectFileConstants.HintPath, null); } - // Get the list of items which require HintPath - IEnumerable references = this.ProjectMgr.BuildProject.GetItems(MsBuildGeneratedItemType.ReferenceCopyLocalPaths); - // Now loop through the generated References to find the corresponding one - foreach (MSBuild.ProjectItem reference in references) + foreach (ProjectItemInstance reference in references) { string fileName = Path.GetFileNameWithoutExtension(reference.EvaluatedInclude); if(String.Compare(fileName, this.assemblyName.Name, StringComparison.OrdinalIgnoreCase) == 0) { // We found it, now set some properties based on this. string hintPath = reference.GetMetadataValue(ProjectFileConstants.HintPath); - this.SetHintPathAndPrivateValue(hintPath); + if (!string.IsNullOrEmpty(hintPath)) + { + if(Path.IsPathRooted(hintPath)) + { + hintPath = PackageUtilities.GetPathDistance(this.ProjectMgr.BaseURI.Uri, new Uri(hintPath)); + } + + this.ItemNode.SetMetadata(ProjectFileConstants.HintPath, hintPath); + + // If this is not already set, we default to true + if(String.IsNullOrEmpty(privateValue)) + { + this.ItemNode.SetMetadata(ProjectFileConstants.Private, true.ToString()); + } + } break; } } } - /// - /// Sets the hint path to the provided value. - /// It also sets the private value to true if it has not been already provided through the associated project element. - /// - /// The hint path to set. - private void SetHintPathAndPrivateValue(string hintPath) - { - if (String.IsNullOrEmpty(hintPath)) - { - return; - } - - if (Path.IsPathRooted(hintPath)) - { - hintPath = PackageUtilities.GetPathDistance(this.ProjectMgr.BaseURI.Uri, new Uri(hintPath)); - } - - this.ItemNode.SetMetadata(ProjectFileConstants.HintPath, hintPath); - - // Private means local copy; we want to know if it is already set to not override the default - string privateValue = this.ItemNode != null ? this.ItemNode.GetMetadata(ProjectFileConstants.Private) : null; - - // If this is not already set, we default to true - if (String.IsNullOrEmpty(privateValue)) - { - this.ItemNode.SetMetadata(ProjectFileConstants.Private, true.ToString()); - } - } - /// /// This function ensures that some properties of the reference are set. /// private void SetReferenceProperties() { - // If there is an assembly path then just set the hint path - if (!string.IsNullOrEmpty(this.assemblyPath)) - { - this.SetHintPathAndPrivateValue(this.assemblyPath); - return; - } - // Set a default HintPath for msbuild to be able to resolve the reference. this.ItemNode.SetMetadata(ProjectFileConstants.HintPath, this.assemblyPath); @@ -454,10 +436,11 @@ namespace Microsoft.VisualStudio.Project } // Check if we have to resolve again the path to the assembly. - this.ResolveReference(); - - // Make sure that the hint path if set (if needed). - this.SetHintPathAndPrivateValue(); + if (!string.IsNullOrEmpty(this.assemblyPath)) + { + ResolveReference(); + SetHintPathAndPrivateValue(); + } } /// diff --git a/source/MPF/12.0/ConfigProvider.cs b/source/MPF/12.0/ConfigProvider.cs index 1f3726b33..4e7507f7e 100644 --- a/source/MPF/12.0/ConfigProvider.cs +++ b/source/MPF/12.0/ConfigProvider.cs @@ -130,6 +130,11 @@ namespace Microsoft.VisualStudio.Project /// An instance of a ProjectConfig object. protected ProjectConfig GetProjectConfiguration(string configName) { + if (configName == null) + { + return null; + } + // if we already created it, return the cached one if(configurationsList.ContainsKey(configName)) { diff --git a/source/MPF/12.0/IDEBuildLogger.cs b/source/MPF/12.0/IDEBuildLogger.cs index f2ce81959..9dd7c57a8 100644 --- a/source/MPF/12.0/IDEBuildLogger.cs +++ b/source/MPF/12.0/IDEBuildLogger.cs @@ -336,6 +336,8 @@ namespace Microsoft.VisualStudio.Project { // NOTE: This may run on a background thread! QueueOutputEvent(messageEvent.Importance, messageEvent); + if(messageEvent.Importance == MessageImportance.High) + QueueTaskEvent(messageEvent); } #endregion @@ -449,6 +451,12 @@ namespace Microsoft.VisualStudio.Project task.Column = warningArgs.ColumnNumber; task.Priority = TaskPriority.Normal; } + else if (errorEvent is BuildMessageEventArgs) + { + BuildMessageEventArgs messageArgs = (BuildMessageEventArgs)errorEvent; + task.ErrorCategory = TaskErrorCategory.Message; + task.Priority = TaskPriority.Normal; + } task.Text = errorEvent.Message; task.Category = TaskCategory.BuildCompile; @@ -509,7 +517,7 @@ namespace Microsoft.VisualStudio.Project /// /// This method takes a MessageImportance and returns true if messages - /// at importance i should be loggeed. Otherwise return false. + /// at importance i should be logged. Otherwise return false. /// private bool LogAtImportance(MessageImportance importance) { diff --git a/source/MPF/12.0/ProjectReferenceNode.cs b/source/MPF/12.0/ProjectReferenceNode.cs index f49be71e9..850e61742 100644 --- a/source/MPF/12.0/ProjectReferenceNode.cs +++ b/source/MPF/12.0/ProjectReferenceNode.cs @@ -174,61 +174,8 @@ namespace Microsoft.VisualStudio.Project { return null; } - foreach (EnvDTE.Project prj in dte.Solution.Projects) - { - //Skip this project if it is an umodeled project (unloaded) - if (string.Compare(EnvDTE.Constants.vsProjectKindUnmodeled, prj.Kind, StringComparison.OrdinalIgnoreCase) == 0) - { - continue; - } - // Get the full path of the current project. - EnvDTE.Property pathProperty = null; - try - { - if (prj.Properties == null) - { - continue; - } - - pathProperty = prj.Properties.Item("FullPath"); - if (null == pathProperty) - { - // The full path should alway be availabe, but if this is not the - // case then we have to skip it. - continue; - } - } - catch (ArgumentException) - { - continue; - } - string prjPath = pathProperty.Value.ToString(); - EnvDTE.Property fileNameProperty = null; - // Get the name of the project file. - try - { - fileNameProperty = prj.Properties.Item("FileName"); - if (null == fileNameProperty) - { - // Again, this should never be the case, but we handle it anyway. - continue; - } - } - catch (ArgumentException) - { - continue; - } - prjPath = System.IO.Path.Combine(prjPath, fileNameProperty.Value.ToString()); - - // If the full path of this project is the same as the one of this - // reference, then we have found the right project. - if (NativeMethods.IsSamePath(prjPath, referencedProjectFullPath)) - { - this.referencedProject = prj; - break; - } - } + this.referencedProject = this.FindReferencedProject(dte.Solution.Projects); } return this.referencedProject; @@ -554,6 +501,97 @@ namespace Microsoft.VisualStudio.Project return circular != 0; } + + private EnvDTE.Project FindReferencedProject(System.Collections.IEnumerable projects) + { + EnvDTE.Project refProject = null; + + // Search for the project in the collection of the projects in the current solution. + foreach (EnvDTE.Project prj in projects) + { + //Skip this project if it is an umodeled project (unloaded) + if (string.Compare(EnvDTE.Constants.vsProjectKindUnmodeled, prj.Kind, StringComparison.OrdinalIgnoreCase) == 0) + { + continue; + } + + // Recursively iterate solution folder for the project. + if (string.Compare(EnvDTE.Constants.vsProjectKindSolutionItems, prj.Kind, StringComparison.OrdinalIgnoreCase) == 0) + { + var containedProjects = GetContainerProjects(prj); + + refProject = FindReferencedProject(containedProjects); + if (refProject != null) + return refProject; + } + + // Get the full path of the current project. + EnvDTE.Property pathProperty = null; + try + { + if (prj.Properties == null) + { + continue; + } + + pathProperty = prj.Properties.Item("FullPath"); + if (null == pathProperty) + { + // The full path should alway be availabe, but if this is not the + // case then we have to skip it. + continue; + } + } + catch (ArgumentException) + { + continue; + } + string prjPath = pathProperty.Value.ToString(); + EnvDTE.Property fileNameProperty = null; + // Get the name of the project file. + try + { + fileNameProperty = prj.Properties.Item("FileName"); + if (null == fileNameProperty) + { + // Again, this should never be the case, but we handle it anyway. + continue; + } + } + catch (ArgumentException) + { + continue; + } + prjPath = System.IO.Path.Combine(prjPath, fileNameProperty.Value.ToString()); + + // If the full path of this project is the same as the one of this + // reference, then we have found the right project. + if (NativeMethods.IsSamePath(prjPath, referencedProjectFullPath)) + { + refProject = prj; + break; + } + } + return refProject; + } + + private static System.Collections.IEnumerable GetContainerProjects(EnvDTE.Project prj) + { + foreach (var obj in prj.ProjectItems) + { + var pi = obj as EnvDTE.ProjectItem; + if (pi == null) + { + continue; + } + + var nestedPrj = pi.Object as EnvDTE.Project; + if (nestedPrj != null) + { + yield return nestedPrj; + } + } + } #endregion }