public static IEnumerable<MBEV.ResolvedImport> Children(this MBEV.ResolvedImport import, MBEV.Project project) { return project.Imports.Where( i => string.Equals(i.ImportingElement.ContainingProject.FullPath, project.ResolveAllProperties(import.ImportedProject.Location.File), StringComparison.OrdinalIgnoreCase)); }
public void PreProcess(MSBuild.Project project) { if (project.ProjectFileLocation.File.EndsWith(".user", System.StringComparison.OrdinalIgnoreCase)) { return; } project.SetProperty("ProjectTypeGuids", "{00251F00-BA30-4CE4-96A2-B8A1085F37AA};{3AF33F2E-1136-4D97-BBB7-1795711AC8B8};{9092AA53-FB77-4645-B42D-1CCCA6BD08BD}"); project.SetProperty("VisualStudioVersion", "14.0"); project.Xml.AddProperty("VisualStudioVersion", "14.0").Condition = "'$(VisualStudioVersion)' == ''"; project.Xml.AddProperty("VSToolsPath", "$(MSBuildExtensionsPath32)\\Microsoft\\VisualStudio\\v$(VisualStudioVersion)").Condition = "'$(VSToolsPath)' == ''"; project.Xml.AddImport("$(VSToolsPath)\\Node.js Tools\\Microsoft.NodejsUwp.targets"); project.SetProperty("ProjectHome", "."); project.SetProperty("ProjectView", "ShowAllFiles"); project.SetProperty("OutputPath", "."); project.SetProperty("AppContainerApplication", "true"); project.SetProperty("ApplicationType", "Windows Store"); project.SetProperty("OutpApplicationTypeRevisionutPath", "8.2"); project.SetProperty("AppxPackage", "true"); project.SetProperty("WindowsAppContainer", "true"); project.SetProperty("RemoteDebugEnabled", "true"); project.SetProperty("PlatformAware", "true"); project.SetProperty("AvailablePlatforms", "x86,x64,ARM"); // Add package.json string jsonStr = "{\"name\": \"HelloWorld\",\"version\": \"0.0.0\",\"main\": \"server.js\"}"; string jsonPath = string.Format("{0}\\package.json", project.DirectoryPath); using (FileStream fs = File.Create(jsonPath)) { fs.Write(Encoding.ASCII.GetBytes(jsonStr), 0, jsonStr.Length); } ProjectItemGroupElement itemGroup = project.Xml.AddItemGroup(); itemGroup.AddItem("Content", jsonPath); }
/// <summary> /// Constructor to Wrap an existing MSBuild.ProjectItem /// Only have internal constructors as the only one who should be creating /// such object is the project itself (see Project.CreateFileNode()). /// </summary> /// <param name="project">Project that owns this item</param> /// <param name="existingItem">an MSBuild.ProjectItem; can be null if virtualFolder is true</param> /// <param name="virtualFolder">Is this item virtual (such as reference folder)</param> internal MsBuildProjectElement(ProjectNode project, MSBuild.ProjectItem existingItem) : base(project) { Utilities.ArgumentNotNull("existingItem", existingItem); // Keep a reference to project and item _item = existingItem; }
private static void PrintPropertyInfo(MBEV.ProjectProperty property, int indentCount) { var indent = new string('\t', indentCount); string location; if (property.IsEnvironmentProperty) { location = "(environment)"; } else if (property.IsReservedProperty) { location = "(reserved)"; } else { location = $"{property.Xml.Location.File}:{property.Xml.Location.Line}"; } Utils.WriteColor($"{indent}Loc: ", ConsoleColor.White); Utils.WriteLineColor(location, ConsoleColor.DarkCyan); if (property.UnevaluatedValue == property.EvaluatedValue) { Utils.WriteColor($"{indent}Val: ", ConsoleColor.White); Utils.WriteLineColor(property.EvaluatedValue, ConsoleColor.Green); } else { Utils.WriteColor($"{indent}Val: ", ConsoleColor.White); Utils.WriteLineColor(property.UnevaluatedValue, ConsoleColor.DarkGreen); Utils.WriteColor($"{indent} ", ConsoleColor.White); Utils.WriteLineColor(property.EvaluatedValue, ConsoleColor.Green); } }
/// <summary> /// Executes the task. /// </summary> /// <returns>True if the task executed successfully; otherwise, false.</returns> public bool Execute() { var fullPath = SourceProjectPath; var basePath = Path.GetDirectoryName( fullPath ); var project = ProjectCollection.GlobalProjectCollection.LoadProject( fullPath ); try { var assemblyInfos = from item in project.GetItems( "Compile" ) let include = item.EvaluatedInclude where include.EndsWith( "AssemblyInfo.cs", StringComparison.OrdinalIgnoreCase ) let itemPath = Path.GetFullPath( Path.Combine( basePath, include ) ) let code = File.ReadAllText( itemPath ) select CSharpSyntaxTree.ParseText( code ); var references = new[] { MetadataReference.CreateFromFile( typeof( object ).Assembly.Location ) }; var compilation = CSharpCompilation.Create( project.GetPropertyValue( "AssemblyName" ), assemblyInfos, references ); var attributes = compilation.Assembly.GetAttributes().ToArray(); IsValid = true; PopulateMetadataFromAttributes( attributes ); } finally { ProjectCollection.GlobalProjectCollection.UnloadProject( project ); } return IsValid; }
public override void Generate(ProjectType projectType, MSBuild.Project project) { var filename = Path.Combine(project.DirectoryPath, Name); File.WriteAllText(filename, Content); if (!IsExcluded) { project.AddItem("Content", Name); } }
public void Trace(MBEV.ResolvedImport import, int traceLevel = 0) { PrintImportInfo(import, traceLevel); foreach (var childImport in import.Children(project)) { Trace(childImport, traceLevel + $"{import.ImportingElement.Location.Line}: ".Length); } }
public override void Generate(ProjectType projectType, MSBuild.Project project) { var target = project.Xml.AddTarget(Name); if (!string.IsNullOrEmpty(DependsOnTargets)) { target.DependsOnTargets = DependsOnTargets; } foreach (var creator in Creators) { creator(target); } }
public override void Generate(ProjectType projectType, MSBuild.Project project) { if (!IsMissing) { Directory.CreateDirectory(Path.Combine(project.DirectoryPath, Name)); } if (!IsExcluded) { project.AddItem("Folder", Name); } }
public override void Generate(ProjectType projectType, MSBuild.Project project) { if (!IsMissing) { var absName = Path.IsPathRooted(Name) ? Name : Path.Combine(project.DirectoryPath, Name); var absReferencePath = Path.IsPathRooted(ReferencePath) ? ReferencePath : Path.Combine(project.DirectoryPath, ReferencePath); NativeMethods.CreateSymbolicLink(absName, absReferencePath); } if (!IsExcluded) { project.AddItem("Folder", Name); } }
public void PreProcess(MSBuild.Project project) { project.SetProperty("ProjectHome", "."); project.SetProperty("WorkingDirectory", "."); project.Xml.AddProperty("VisualStudioVersion", "11.0").Condition = "'$(VisualStudioVersion)' == ''"; project.Xml.AddProperty("PtvsTargetsFile", "$(MSBuildExtensionsPath32)\\Microsoft\\VisualStudio\\v$(VisualStudioVersion)\\Python Tools\\Microsoft.PythonTools.targets"); var import1 = project.Xml.AddImport("$(PtvsTargetsFile)"); import1.Condition = "Exists($(PtvsTargetsFile))"; var import2 = project.Xml.AddImport("$(MSBuildToolsPath)\\Microsoft.Common.targets"); import2.Condition = "!Exists($(PtvsTargetsFile))"; }
public void UpdateProject(PythonProjectNode node, MSBuild.Project project) { lock (_projects) { if (project == null) { _projects.Remove(node); } else if (!_projects.ContainsKey(node) || _projects[node] != project) { _projects[node] = project; } } // Always raise the event, this also occurs when we're adding projects // to the MSBuild.Project. ProjectsChanaged?.Invoke(this, EventArgs.Empty); }
public static void Trace(MBEV.ProjectProperty property, int traceLevel = 0) { if (property == null || property.IsGlobalProperty || property.IsReservedProperty) { return; } PrintPropertyInfo(property, traceLevel); if (property.IsImported) { Trace(property.Predecessor, traceLevel + 1); } }
/// <summary> /// Creates a new provider for the specified project and service. /// </summary> public MSBuildProjectInterpreterFactoryProvider(IInterpreterOptionsService service, MSBuild.Project project) { if (service == null) { throw new ArgumentNullException("service"); } if (project == null) { throw new ArgumentNullException("project"); } _rootPaths = new Dictionary<Guid, string>(); _service = service; _project = project; // _active starts as null, so we need to start with this event // hooked up. _service.DefaultInterpreterChanged += GlobalDefaultInterpreterChanged; }
public CogaenEditProject(Package pkg, IOleServiceProvider site, MSBuild.Project buildProject) { this.package = pkg; SetSite(site); this.BuildProject = buildProject; this.CanFileNodesHaveChilds = true; this.OleServiceProvider.AddService(typeof(VSLangProj.VSProject), new OleServiceProvider.ServiceCreatorCallback(this.CreateServices), false); this.SupportsProjectDesigner = true; //Store the number of images in ProjectNode so we know the offset of the python icons. ImageOffset = this.ImageHandler.ImageList.Images.Count; foreach (Image img in CogaenEditImageList.Images) { this.ImageHandler.AddImage(img); } InitializeCATIDs(); }
/// <summary> /// Gets a collection of ProjectTargetInstances that this target is dependent on in a given project. /// </summary> /// <param name="target"></param> /// <param name="project">The project to look in</param> /// <returns></returns> public static IEnumerable<MBEX.ProjectTargetInstance> Dependencies( this MBEX.ProjectTargetInstance target, MBEV.Project project) { var dependencies = new List<MBEX.ProjectTargetInstance>(); var dependencyTargetNames = project.ResolveAllProperties(target.DependsOnTargets) .Replace(Environment.NewLine, "") .Split(';'); foreach (var name in dependencyTargetNames) { if (!string.IsNullOrWhiteSpace(name)) { dependencies.Add(project.Targets[name.Trim()]); } } return dependencies; }
public override void Generate(ProjectType projectType, MSBuild.Project project) { var filename = Path.Combine(project.DirectoryPath, Name + projectType.CodeExtension); if (!IsMissing) { File.WriteAllText(filename, Content ?? projectType.SampleCode); } if (!IsExcluded) { List<KeyValuePair<string, string>> metadata = new List<KeyValuePair<string, string>>(); if (LinkFile != null) { metadata.Add(new KeyValuePair<string, string>("Link", LinkFile + projectType.CodeExtension)); } project.AddItem( "Compile", Name + projectType.CodeExtension, metadata ); } }
public void PostProcess(MSBuild.Project project) { var projectExt = project.Xml.CreateProjectExtensionsElement(); projectExt.Content = @" <VisualStudio> <FlavorProperties GUID=""{349c5851-65df-11da-9384-00065b846f21}""> <WebProjectProperties> <UseIIS>False</UseIIS> <AutoAssignPort>True</AutoAssignPort> <DevelopmentServerPort>0</DevelopmentServerPort> <DevelopmentServerVPath>/</DevelopmentServerVPath> <IISUrl>http://localhost:48022/</IISUrl> <NTLMAuthentication>False</NTLMAuthentication> <UseCustomServer>True</UseCustomServer> <CustomServerUrl>http://localhost:1337</CustomServerUrl> <SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile> </WebProjectProperties> </FlavorProperties> <FlavorProperties GUID=""{349c5851-65df-11da-9384-00065b846f21}"" User=""""> <WebProjectProperties> <StartPageUrl> </StartPageUrl> <StartAction>CurrentPage</StartAction> <AspNetDebugging>True</AspNetDebugging> <SilverlightDebugging>False</SilverlightDebugging> <NativeDebugging>False</NativeDebugging> <SQLDebugging>False</SQLDebugging> <ExternalProgram> </ExternalProgram> <StartExternalURL> </StartExternalURL> <StartCmdLineArguments> </StartCmdLineArguments> <StartWorkingDirectory> </StartWorkingDirectory> <EnableENC>False</EnableENC> <AlwaysStartWebServerOnDebug>False</AlwaysStartWebServerOnDebug> </WebProjectProperties> </FlavorProperties> </VisualStudio> "; project.Xml.AppendChild(projectExt); }
private void PrintImportInfo(MBEV.ResolvedImport import, int indentLength) { var indent = indentLength > 0 ? new StringBuilder().Insert(0, " ", indentLength).ToString() : ""; Utils.WriteColor(indent, ConsoleColor.White); Utils.WriteColor($"{import.ImportingElement.Location.Line}: ", ConsoleColor.Cyan); var importedProjectFile = project.ResolveAllProperties(import.ImportedProject.Location.File); Utils.WriteColor(Path.GetDirectoryName(importedProjectFile) + Path.DirectorySeparatorChar, ConsoleColor.DarkGreen); Utils.WriteLineColor(Path.GetFileName(importedProjectFile), ConsoleColor.Green); if (!string.IsNullOrWhiteSpace(import.ImportingElement.Condition)) { Utils.WriteColor($"{indent}because ", ConsoleColor.DarkGray); Utils.WriteLineColor($"{import.ReducedCondition()}", ConsoleColor.DarkCyan); } Console.WriteLine(); }
public MSBuild.Project Save(MSBuild.ProjectCollection collection, string location) { location = Path.Combine(location, _name); Directory.CreateDirectory(location); var project = new MSBuild.Project(collection); string projectFile = Path.Combine(location, _name) + ProjectType.ProjectExtension; if (_isUserProject) { projectFile += ".user"; } project.Save(projectFile); if (ProjectType != ProjectType.Generic) { var projGuid = Guid; project.SetProperty("ProjectTypeGuid", TypeGuid.ToString()); project.SetProperty("Name", _name); project.SetProperty("ProjectGuid", projGuid.ToString("B")); project.SetProperty("SchemaVersion", "2.0"); var group = project.Xml.AddPropertyGroup(); group.Condition = " '$(Configuration)' == 'Debug' "; group.AddProperty("DebugSymbols", "true"); group = project.Xml.AddPropertyGroup(); group.Condition = " '$(Configuration)' == 'Release' "; group.AddProperty("DebugSymbols", "false"); } foreach (var processor in ProjectType.Processors) { processor.PreProcess(project); } foreach (var item in Items) { item.Generate(ProjectType, project); } foreach (var processor in ProjectType.Processors) { processor.PostProcess(project); } project.Save(); return project; }
public void PreProcess(MSBuild.Project project) { if (project.ProjectFileLocation.File.EndsWith(".user", System.StringComparison.OrdinalIgnoreCase)) { return; } project.SetProperty("ProjectTypeGuids", "{00251F00-BA30-4CE4-96A2-B8A1085F37AA};{3AF33F2E-1136-4D97-BBB7-1795711AC8B8};{9092AA53-FB77-4645-B42D-1CCCA6BD08BD}"); project.SetProperty("VisualStudioVersion", "14.0"); project.Xml.AddProperty("VisualStudioVersion", "14.0").Condition = "'$(VisualStudioVersion)' == ''"; project.Xml.AddProperty("VSToolsPath", "$(MSBuildExtensionsPath32)\\Microsoft\\VisualStudio\\v$(VisualStudioVersion)").Condition = "'$(VSToolsPath)' == ''"; project.Xml.AddImport("$(VSToolsPath)\\Node.js Tools\\Microsoft.NodejsUwp.targets"); project.SetProperty("ProjectHome", "."); project.SetProperty("ProjectView", "ShowAllFiles"); project.SetProperty("OutputPath", "."); project.SetProperty("AppContainerApplication", "true"); project.SetProperty("ApplicationType", "Windows Store"); project.SetProperty("OutpApplicationTypeRevisionutPath", "8.2"); project.SetProperty("AppxPackage", "true"); project.SetProperty("WindowsAppContainer", "true"); project.SetProperty("RemoteDebugEnabled", "true"); project.SetProperty("PlatformAware", "true"); project.SetProperty("AvailablePlatforms", "x86,x64,ARM"); }
public void PreProcess(MSBuild.Project project) { if (project.ProjectFileLocation.File.EndsWith(".user", System.StringComparison.OrdinalIgnoreCase)) { return; } // Node.js projects are flavored which enables a lot of our functionality, so // setup our flavor. project.SetProperty("ProjectTypeGuids", "{3AF33F2E-1136-4D97-BBB7-1795711AC8B8};{349c5851-65df-11da-9384-00065b846f21};{9092AA53-FB77-4645-B42D-1CCCA6BD08BD}"); var prop = project.SetProperty("VisualStudioVersion", "14.0"); project.Xml.AddProperty("VisualStudioVersion", "14.0").Condition = "'$(VisualStudioVersion)' == ''"; project.Xml.AddProperty("VSToolsPath", "$(MSBuildExtensionsPath32)\\Microsoft\\VisualStudio\\v$(VisualStudioVersion)").Condition = "'$(VSToolsPath)' == ''"; var import = project.Xml.AddImport("$(MSBuildExtensionsPath)\\$(MSBuildToolsVersion)\\Microsoft.Common.props"); import.Condition = "Exists('$(MSBuildExtensionsPath)\\$(MSBuildToolsVersion)\\Microsoft.Common.props')"; project.Xml.AddImport("$(VSToolsPath)\\Node.js Tools\\Microsoft.NodejsTools.targets"); project.SetProperty("ProjectHome", "."); project.SetProperty("WorkingDirectory", "."); project.SetProperty("ProjectView", "ShowAllFiles"); project.SetProperty("OutputPath", "."); }
private void DiscoverTests(Dictionary<string, List<TestFileEntry>> testItems, MSBuild.Project proj, ITestCaseDiscoverySink discoverySink, IMessageLogger logger) { List<TestFrameworks.NodejsTestInfo> result = new List<TestFrameworks.NodejsTestInfo>(); var projectHome = Path.GetFullPath(Path.Combine(proj.DirectoryPath, ".")); var projSource = ((MSBuild.Project)proj).FullPath; var nodeExePath = Nodejs.GetAbsoluteNodeExePath( projectHome, proj.GetPropertyValue(NodejsConstants.NodeExePath)); if (!File.Exists(nodeExePath)) { logger.SendMessage(TestMessageLevel.Error, String.Format("Node.exe was not found. Please install Node.js before running tests.")); return; } int testCount = 0; foreach (string testFx in testItems.Keys) { TestFrameworks.TestFramework testFramework = GetTestFrameworkObject(testFx); if (testFramework == null) { logger.SendMessage(TestMessageLevel.Warning, String.Format("Ignoring unsupported test framework {0}", testFx)); continue; } List<TestFileEntry> fileList = testItems[testFx]; string files = string.Join(";", fileList.Select(p=>p.File)); logger.SendMessage(TestMessageLevel.Informational, String.Format("Processing: {0}", files)); List<TestFrameworks.NodejsTestInfo> discoveredTestCases = testFramework.FindTests(fileList.Select(p => p.File), nodeExePath, logger, projectHome); testCount += discoveredTestCases.Count; foreach (TestFrameworks.NodejsTestInfo discoveredTest in discoveredTestCases) { string qualifiedName = discoveredTest.FullyQualifiedName; logger.SendMessage(TestMessageLevel.Informational, String.Format(" " /*indent*/ + "Creating TestCase:{0}", qualifiedName)); //figure out the test source info such as line number string filePath = discoveredTest.ModulePath; TestFileEntry entry = fileList.Find(p => p.File.Equals(filePath, StringComparison.OrdinalIgnoreCase)); FunctionInformation fi = null; if (entry.IsTypeScriptTest) { fi = SourceMapper.MaybeMap(new FunctionInformation(String.Empty, discoveredTest.TestName, discoveredTest.SourceLine, entry.File)); } discoverySink.SendTestCase( new TestCase(qualifiedName, TestExecutor.ExecutorUri, projSource) { CodeFilePath = (fi != null) ? fi.Filename : filePath, LineNumber = (fi != null && fi.LineNumber.HasValue) ? fi.LineNumber.Value : discoveredTest.SourceLine, DisplayName = discoveredTest.TestName }); } logger.SendMessage(TestMessageLevel.Informational, string.Format("Processing finished for framework of {0}", testFx)); } if (testCount == 0) { logger.SendMessage(TestMessageLevel.Warning, String.Format("Discovered 0 testcases.")); } }
internal static MSBuild.Project LoadProject(MSBuild.ProjectCollection buildEngine, string fullProjectPath) { var buildProject = buildEngine.GetLoadedProjects(fullProjectPath).FirstOrDefault(); if (buildProject != null) { buildEngine.UnloadProject(buildProject); } return buildEngine.LoadProject(fullProjectPath); }
public PropertyStorageLocations GetLocation(MSBuild.ProjectProperty prop) { var location = MSBuildInternals.GetLocationFromCondition(prop.Xml); if (prop.Xml.ContainingProject == p.userProjectFile) location |= PropertyStorageLocations.UserFile; return location; }
internal ConfiguredProject(MSBuildBasedProject parent, MSBuild.Project project, bool unloadProjectOnDispose) { this.p = parent; this.Project = project; this.unloadProjectOnDispose = unloadProjectOnDispose; }
private void ReplaceGuidMetadataIfExists(_BE.ProjectItem item, string metadataName) { string value = item.GetMetadata(metadataName).EvaluatedValue; if (!string.IsNullOrEmpty(value)) { try { Guid g = new Guid(value); string replaceWith; if (guidDictionary.TryGetValue(g, out replaceWith)) { //VS Guid replacements don't include braces replaceWith = "{" + replaceWith + "}"; item.SetMetadataValue(metadataName, replaceWith); } } catch (FormatException) { Log.LogWarning("Item {0} has specified {1} metadata not in the format of a Guid.", item.EvaluatedInclude, metadataName); } } }
/// <summary> /// Adds references to this container from a MSBuild project. /// </summary> public void LoadReferencesFromBuildProject(MSBuild.Project buildProject) { ProjectMgr.Site.GetUIThread().MustBeCalledFromUIThread(); foreach (string referenceType in SupportedReferenceTypes) { IEnumerable<MSBuild.ProjectItem> referencesGroup = this.ProjectMgr.BuildProject.GetItems(referenceType); bool isAssemblyReference = referenceType == ProjectFileConstants.Reference; // If the project was loaded for browsing we should still create the nodes but as not resolved. if (isAssemblyReference && (!ProjectMgr.BuildProject.Targets.ContainsKey(MsBuildTarget.ResolveAssemblyReferences) || this.ProjectMgr.Build(MsBuildTarget.ResolveAssemblyReferences) != MSBuildResult.Successful)) { continue; } foreach (MSBuild.ProjectItem item in referencesGroup) { ProjectElement element = new MsBuildProjectElement(this.ProjectMgr, item); ReferenceNode node = CreateReferenceNode(referenceType, element); if (node != null) { // Make sure that we do not want to add the item twice to the ui hierarchy // We are using here the UI representation of the Node namely the Caption to find that out, in order to // avoid different representation problems. // Example :<Reference Include="EnvDTE80, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> // <Reference Include="EnvDTE80" /> bool found = false; for (HierarchyNode n = this.FirstChild; n != null && !found; n = n.NextSibling) { if (String.Compare(n.Caption, node.Caption, StringComparison.OrdinalIgnoreCase) == 0) { found = true; } } if (!found) { this.AddChild(node); } } } } }
/// <summary> /// Set the build project with the new project instance value /// </summary> /// <param name="project">The new build project instance</param> private void SetBuildProject(MSBuild.Project project) { this.buildProject = project; if (this.buildProject != null) { SetupProjectGlobalPropertiesThatAllProjectSystemsMustSet(); } }
/// <summary> /// Get the parent node of an msbuild item /// </summary> /// <param name="item">msbuild item</param> /// <returns>parent node</returns> private HierarchyNode GetItemParentNode(MSBuild.ProjectItem item) { HierarchyNode currentParent = this; string strPath = item.EvaluatedInclude; strPath = Path.GetDirectoryName(strPath); if (strPath.Length > 0) { // Use the relative to verify the folders... currentParent = this.CreateFolderNodes(strPath); } return currentParent; }