/// <summary> /// Creates a temporary MSBuild content project in memory. /// </summary> void CreateBuildProject() { string projectPath = Path.Combine(buildDirectory, "content.contentproj"); string outputPath = Path.Combine(buildDirectory, "bin"); // Create the build project. projectRootElement = ProjectRootElement.Create(projectPath); // Include the standard targets file that defines how to build XNA Framework content. projectRootElement.AddImport("$(MSBuildExtensionsPath)\\Microsoft\\XNA Game Studio\\" + "v4.0\\Microsoft.Xna.GameStudio.ContentPipeline.targets"); buildProject = new Microsoft.Build.Evaluation.Project(projectRootElement); buildProject.SetProperty("XnaPlatform", "Windows"); buildProject.SetProperty("XnaProfile", "Reach"); buildProject.SetProperty("XnaFrameworkVersion", "v4.0"); buildProject.SetProperty("Configuration", "Release"); buildProject.SetProperty("OutputPath", outputPath); // Register any custom importers or processors. foreach (string pipelineAssembly in pipelineAssemblies) { buildProject.AddItem("Reference", pipelineAssembly); } // Hook up our custom error logger. errorLogger = new ErrorLogger(); buildParameters = new BuildParameters(ProjectCollection.GlobalProjectCollection); buildParameters.Loggers = new ILogger[] { errorLogger }; }
public void PreProcess(MSBuild.Project project) { project.SetProperty("ProjectHome", "."); project.SetProperty("WorkingDirectory", "."); project.Xml.AddImport(Microsoft.PythonTools.Project.PythonProjectFactory.PtvsTargets); }
public static void PrepareForChecking(Project proj, string startupObject, IReadOnlyList<string> excludedPaths) { proj.SetProperty("StartupObject", startupObject); proj.SetProperty("OutputType", "Exe"); proj.SetProperty("UseVSHostingProcess", "false"); ResolveLinks(proj); ExcludePaths(proj, excludedPaths); }
public void PreProcess(MSBuild.Project project) { project.SetProperty("ProjectHome", "."); project.SetProperty("WorkingDirectory", "."); var installPath = PathUtils.GetParent(PythonToolsInstallPath.GetFile("Microsoft.PythonTools.dll", typeof(PythonToolsPackage).Assembly)); project.SetProperty("_PythonToolsPath", installPath); project.Xml.AddImport(Microsoft.PythonTools.Project.PythonProjectFactory.PtvsTargets); }
private static string GetPropertyValueFrom(string projectFile, string propertyName, string solutionDir, string configurationName) { using (var projectCollection = new ProjectCollection()) { var p = new Project(projectFile, null, null, projectCollection, ProjectLoadSettings.Default); p.SetProperty("Configuration", configurationName); p.SetProperty("SolutionDir", solutionDir); p.SetGlobalProperty("SolutionDir", solutionDir); p.ReevaluateIfNecessary(); return(p.Properties.Where(x => x.Name == propertyName).Select(x => x.EvaluatedValue).SingleOrDefault()); } }
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 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.NewGuid(); 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 static MSbuildResult BuildProject(MsBuildSettings settings, string projectFileName, DirectoryInfo dir) { var result = new MSbuildResult(); var path = Path.Combine(dir.FullName, projectFileName); var project = new Project(path, null, null, new ProjectCollection()); project.SetProperty("CscToolPath", settings.CompilerDirectory.FullName); var includes = new HashSet<string>( project.AllEvaluatedItems .Where(i => i.ItemType == "None" || i.ItemType == "Content") .Select(i => Path.GetFileName(i.EvaluatedInclude.ToLowerInvariant()))); foreach (var dll in settings.WellKnownLibsDirectory.GetFiles("*.dll")) if (!includes.Contains(dll.Name.ToLowerInvariant())) project.AddItem("None", dll.FullName); project.Save(); using (var stringWriter = new StringWriter()) { var logger = new ConsoleLogger(LoggerVerbosity.Minimal, stringWriter.Write, color => { }, () => { }); result.Success = SyncBuild(project, logger); if (result.Success) result.PathToExe = Path.Combine(project.DirectoryPath, project.GetPropertyValue("OutputPath"), project.GetPropertyValue("AssemblyName") + ".exe"); else result.ErrorMessage = stringWriter.ToString(); return result; } }
public static Project AddConfigurations(Project proj, string defaultConfig) { try { var prop = proj.SetProperty("Configuration", defaultConfig); prop.Xml.Condition = " '$(Configuration)' == '' "; var debugPropGroup = proj.Xml.AddPropertyGroup(); var releasePropGroup = proj.Xml.AddPropertyGroup(); debugPropGroup.Condition = " '$(Configuration)' == 'Release' "; debugPropGroup.SetProperty("OutputPath", "bin\\Release"); debugPropGroup.SetProperty("DebugSymbols", "Fasle"); debugPropGroup.SetProperty("DebugType", "None"); debugPropGroup.SetProperty("Optomize", "True"); debugPropGroup.SetProperty("CheckForOverflowUnderflow", "False"); debugPropGroup.SetProperty("DefineConstants", "TRACE"); releasePropGroup.Condition = " '$(Configuration)' == 'Debug' "; releasePropGroup.SetProperty("OutputPath", "bin\\Debug"); releasePropGroup.SetProperty("DebugSymbols", "True"); releasePropGroup.SetProperty("DebugType", "Full"); releasePropGroup.SetProperty("Optomize", "False"); releasePropGroup.SetProperty("CheckForOverflowUnderflow", "True"); releasePropGroup.SetProperty("DefineConstants", "DEBUG;TRACE"); return proj; } catch { throw; } }
public void ProjectGetter() { Project project = new Project(); ProjectProperty property = project.SetProperty("p", "v"); Assert.Equal(true, Object.ReferenceEquals(project, property.Project)); }
public static ProjectProperty ThreadSafeSetProperty(this Microsoft.Build.Evaluation.Project thisp, string propertyName, string propertyValue) { lock (thisp) { return(thisp.SetProperty(propertyName, propertyValue)); } }
void CreateBuildProject() { string projectPath = Path.Combine(buildDirectory, "content.contentproj"); string outputPath = Path.Combine(buildDirectory, "bin"); // Create the build project. projectRootElement = ProjectRootElement.Create(projectPath); // Include the standard targets file that defines how to build XNA Framework content. projectRootElement.AddImport(Application.StartupPath + "\\Exporters\\FBX\\XNA\\XNA Game Studio\\" + "v4.0\\Microsoft.Xna.GameStudio.ContentPipeline.targets"); buildProject = new Project(projectRootElement); buildProject.SetProperty("XnaPlatform", "Windows"); buildProject.SetProperty("XnaProfile", "Reach"); buildProject.SetProperty("XnaFrameworkVersion", "v4.0"); buildProject.SetProperty("Configuration", "Release"); buildProject.SetProperty("OutputPath", outputPath); buildProject.SetProperty("ContentRootDirectory", "."); buildProject.SetProperty("ReferencePath", Application.StartupPath); // Register any custom importers or processors. foreach (string pipelineAssembly in pipelineAssemblies) { buildProject.AddItem("Reference", pipelineAssembly); } // Hook up our custom error logger. errorLogger = new ErrorLogger(); buildParameters = new BuildParameters(ProjectCollection.GlobalProjectCollection) {Loggers = new ILogger[] {errorLogger}}; }
private static void addPostBuildEvent(string path) { Project project = new Project(path); project.SetProperty("PostBuildEvent", string.Format( @"""{0}"" "" $(TargetDir) "" "" $(TargetName) "" "" $(SolutionDir) """, Process.GetCurrentProcess().MainModule.FileName)); project.Save(); }
public static Project AddGuid(Project proj) { try { var guid = string.Format("{{{0}}}", Guid.NewGuid().ToString().ToUpper()); proj.SetProperty("ProjectGuid", guid); return proj; } catch { throw; } }
/// <summary> /// Creates a DecisionTreeClassifier.exe from a decision tree, returning the file path of the new exe /// </summary> public static string CompileClassifier(TreeNode decisionTree) { var assemblyLocation = Assembly.GetExecutingAssembly().Location; var assemblyDirectory = new FileInfo(assemblyLocation).DirectoryName ?? ""; var classifierDir = Path.Combine(assemblyDirectory, "DecisionTreeClassifier"); var projFullPath = Path.Combine(classifierDir, "DecisionTreeClassifier.csproj"); var mainFullPath = Path.Combine(classifierDir, "Program.cs"); ReplaceSerializedTreeLine(mainFullPath, decisionTree); // load up the classifier project var proj = new Project(projFullPath); // set project to compile special DecisionTree config proj.SetProperty("Configuration", "DecisionTree"); // set the output path proj.SetProperty("DecisionTreeOutputPath", assemblyDirectory); // make a logger to catch possible build errors var logger = new SimpleBuildLogger(); // if we failed to build the classifier, we're screwed if (!proj.Build(logger)) { var sb = new StringBuilder(); sb.AppendLine("***************************************"); sb.AppendLine("**** Failed To Compile Classifier! ****"); sb.AppendLine("***************************************"); foreach (var error in logger.Errors) { sb.AppendLine(error.Message + " " + error.File + ": " + error.LineNumber); } throw new Exception(sb.ToString()); } // return the executable name var exeFileName = proj.GetProperty("AssemblyName").EvaluatedValue + ".exe"; return Path.Combine(assemblyDirectory, exeFileName); }
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; }
private IEnumerable <string> ResolveAssemblyReferences(Microsoft.Build.Evaluation.Project project) { var projectInstance = project.CreateProjectInstance(); projectInstance.SetProperty("BuildingProject", "false"); project.SetProperty("DesignTimeBuild", "true"); projectInstance.Build("ResolveAssemblyReferences", new[] { new ConsoleLogger(LoggerVerbosity.Minimal) }); var items = projectInstance.GetItems("_ResolveAssemblyReferenceResolvedFiles"); return(items.Select(i => Path.Combine(Path.GetDirectoryName(this.FileName), i.GetMetadataValue("Identity")))); }
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", "."); }
public static Project AddPlatform(Project proj, string platformName) { try { var prop = proj.SetProperty("Platform", platformName); prop.Xml.Condition = " '$(Platform)' == '' "; var propGroup = proj.Xml.AddPropertyGroup(); propGroup.Condition = string.Format(" '$(Platform)' == '{0}' ", platformName); propGroup.SetProperty("PlatformGroup", platformName); return proj; } catch { throw; } }
/// <summary> /// Stores the value in current project. /// </summary> /// <param name="selectedFeaturesIds">The selected features ids.</param> /// <param name="sharePointProject">The share point project.</param> /// <param name="projectPropertyName">Name of the project property.</param> public static void StoreValueInCurrentProject(List <string> selectedFeaturesIds, ISharePointProject sharePointProject, string projectPropertyName) { string value = String.Empty; if (selectedFeaturesIds != null && selectedFeaturesIds.Count > 0) { value = String.Join(";", selectedFeaturesIds.ToArray()); } Microsoft.Build.Evaluation.Project project = GetCurrentProject(sharePointProject.FullPath); if (project != null) { project.SetProperty(projectPropertyName, value as string); } }
public void Single() { Project project = new Project(); project.SetProperty("p", "v1"); StringWriter writer = new StringWriter(); project.SaveLogicalProject(writer); string expected = ObjectModelHelpers.CleanupFileContents( @"<?xml version=""1.0"" encoding=""utf-16""?> <Project ToolsVersion=""msbuilddefaulttoolsversion"" xmlns=""msbuildnamespace""> <PropertyGroup> <p>v1</p> </PropertyGroup> </Project>"); Helpers.VerifyAssertLineByLine(expected, writer.ToString()); }
public ContentProject(string outputPath, string projectDir = null) { var rootElement = ProjectRootElement.Create(); rootElement.AddImport(Path.GetFullPath("lib\\Microsoft.Xna.GameStudio.ContentPipeline.targets")); buildProject = new Project(rootElement); buildProject.SetProperty("XnaPlatform", "Windows"); buildProject.SetProperty("XnaProfile", "Reach"); buildProject.SetProperty("XnaFrameworkVersion", "v4.0"); buildProject.SetProperty("Configuration", "Release"); buildProject.SetProperty("OutputPath", outputPath); if (!projectDir.IsNullOrEmpty()) buildProject.SetProperty("BaseIntermediateOutputPath", projectDir.GetRelativePathFrom(Directory.GetCurrentDirectory())); errorLogger = new ConfigurableForwardingLogger { BuildEventRedirector = new NlogEventRedirector() }; buildParams = new BuildParameters(ProjectCollection.GlobalProjectCollection); buildParams.Loggers = new ILogger[] { errorLogger }; }
public void AddItem_MatchesWildcardWithPropertyReference() { Project project = new Project(); project.SetProperty("p", "xxx"); project.Xml.AddItem("i", "a;*.$(p);b"); project.ReevaluateIfNecessary(); project.AddItem("i", "i1.xxx"); string expected = ObjectModelHelpers.CleanupFileContents( @"<Project ToolsVersion=""msbuilddefaulttoolsversion"" xmlns=""msbuildnamespace""> <PropertyGroup> <p>xxx</p> </PropertyGroup> <ItemGroup> <i Include=""a;*.$(p);b"" /> </ItemGroup> </Project>"); Helpers.VerifyAssertProjectContent(expected, project); }
public void RenameItem_NewNameContainsItemExpression() { Project project = new Project(); project.SetProperty("p", "v1"); project.AddItem("h", "h1"); project.AddItem("i", "i1"); project.ReevaluateIfNecessary(); ProjectItem item = Helpers.GetLast(project.Items); item.Rename("@(h)"); Assert.Equal("@(h)", item.UnevaluatedInclude); // Rename should have been expanded in this simple case Assert.Equal("h1", item.EvaluatedInclude); // The ProjectItemElement should be the same ProjectItemElement newItemElement = Helpers.GetLast((Helpers.GetLast(project.Xml.ItemGroups)).Items); Assert.Equal(true, Object.ReferenceEquals(item.Xml, newItemElement)); }
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 AddItem_IncludeContainsPropertyExpression() { Project project = new Project(); project.SetProperty("p", "v1"); project.ReevaluateIfNecessary(); project.AddItem("i", "$(p)"); Assert.Equal("$(p)", Helpers.GetFirst(project.Items).UnevaluatedInclude); Assert.Equal("v1", Helpers.GetFirst(project.Items).EvaluatedInclude); }
public void ChangeEnvironmentProperty() { Project project = new Project(); project.SetProperty("computername", "v1"); Assert.Equal("v1", project.GetPropertyValue("computername")); Assert.Equal(true, project.IsDirty); project.ReevaluateIfNecessary(); Assert.Equal("v1", project.GetPropertyValue("computername")); }
public static bool UpgradeProjectProperties(Microsoft.Build.Evaluation.Project project, bool cpp) { bool modified = false; string outputDir = null; string headerOutputDir = null; string baseDirectoryForGeneratedInclude = null; string value = project.GetProperty(PropertyNames.Old.OutputDir, false); if (!string.IsNullOrEmpty(value)) { project.RemovePropertyWithName(PropertyNames.Old.OutputDir); value = value.Replace("$(IceBuilder", "%("); project.SetItemMetadata(ItemMetadataNames.OutputDir, value); modified = true; outputDir = value; } else if (cpp) { // The default output directory for C++ generated items was changed to $(IntDir) // but we keep the old default when converted projects by setting it in the project // file project.SetItemMetadata(ItemMetadataNames.OutputDir, "generated"); } value = project.GetProperty(PropertyNames.Old.IncludeDirectories, false); if (!string.IsNullOrEmpty(value)) { project.RemovePropertyWithName(PropertyNames.Old.IncludeDirectories); value = value.Replace("$(IceHome)\\slice", ""); value = value.Replace("$(IceHome)/slice", ""); value = value.Trim(';'); value = value.Replace("$(IceBuilder", "%("); if (!string.IsNullOrEmpty(value)) { project.SetItemMetadata(ItemMetadataNames.IncludeDirectories, value); } modified = true; } value = project.GetProperty(PropertyNames.Old.HeaderOutputDir, false); if (!string.IsNullOrEmpty(value)) { project.RemovePropertyWithName(PropertyNames.Old.HeaderOutputDir); value = value.Replace("$(IceBuilder", "%("); project.SetItemMetadata(ItemMetadataNames.HeaderOutputDir, value); modified = true; headerOutputDir = value; } value = project.GetProperty(PropertyNames.Old.HeaderExt, false); if (!string.IsNullOrEmpty(value)) { project.RemovePropertyWithName(PropertyNames.Old.HeaderExt); project.SetItemMetadata(ItemMetadataNames.HeaderExt, value); modified = true; } value = project.GetProperty(PropertyNames.Old.BaseDirectoryForGeneratedInclude, false); if (!string.IsNullOrEmpty(value)) { project.RemovePropertyWithName(PropertyNames.Old.BaseDirectoryForGeneratedInclude); project.SetItemMetadata(ItemMetadataNames.BaseDirectoryForGeneratedInclude, value); modified = true; baseDirectoryForGeneratedInclude = value; } value = project.GetProperty(PropertyNames.Old.SourceExt, false); if (!string.IsNullOrEmpty(value)) { project.RemovePropertyWithName(PropertyNames.Old.SourceExt); project.SetItemMetadata(ItemMetadataNames.SourceExt, value); modified = true; } value = project.GetProperty(PropertyNames.Old.AllowIcePrefix, false); string additionalOptions = project.GetProperty(PropertyNames.Old.AdditionalOptions, false); if (!string.IsNullOrEmpty(additionalOptions)) { project.RemovePropertyWithName(PropertyNames.Old.AdditionalOptions); modified = true; } if (!string.IsNullOrEmpty(value)) { if (value.Equals("yes", StringComparison.CurrentCultureIgnoreCase) || value.Equals("true", StringComparison.CurrentCultureIgnoreCase)) { additionalOptions = String.Format("{0} --ice", additionalOptions).Trim(); } project.RemovePropertyWithName(PropertyNames.Old.AllowIcePrefix); modified = true; } value = project.GetProperty(PropertyNames.Old.Underscore, false); if (!string.IsNullOrEmpty(value)) { if (value.Equals("yes", StringComparison.CurrentCultureIgnoreCase) || value.Equals("true", StringComparison.CurrentCultureIgnoreCase)) { additionalOptions = String.Format("{0} --underscore", additionalOptions).Trim(); } project.RemovePropertyWithName(PropertyNames.Old.Underscore); modified = true; } value = project.GetProperty(PropertyNames.Old.Stream, false); if (!string.IsNullOrEmpty(value)) { if (value.Equals("yes", StringComparison.CurrentCultureIgnoreCase) || value.Equals("true", StringComparison.CurrentCultureIgnoreCase)) { additionalOptions = String.Format("{0} --stream ", additionalOptions).Trim(); } project.RemovePropertyWithName(PropertyNames.Old.Stream); modified = true; } value = project.GetProperty(PropertyNames.Old.DLLExport, false); if (!string.IsNullOrEmpty(value)) { additionalOptions = String.Format("{0} --dll-export {1}", additionalOptions, value).Trim(); project.RemovePropertyWithName(PropertyNames.Old.DLLExport); modified = true; } value = project.GetProperty(PropertyNames.Old.Checksum, false); if (!string.IsNullOrEmpty(value)) { additionalOptions = String.Format("{0} --checksum", additionalOptions).Trim(); project.RemovePropertyWithName(PropertyNames.Old.Checksum); modified = true; } value = project.GetProperty(PropertyNames.Old.Tie, false); if (!string.IsNullOrEmpty(value)) { additionalOptions = String.Format("{0} --tie", additionalOptions).Trim(); project.RemovePropertyWithName(PropertyNames.Old.Tie); modified = true; } if (!string.IsNullOrEmpty(additionalOptions)) { additionalOptions = additionalOptions.Replace("IceBuilder", "SliceCompile"); project.SetItemMetadata(ItemMetadataNames.AdditionalOptions, additionalOptions); } if (string.IsNullOrEmpty(baseDirectoryForGeneratedInclude)) { if (!string.IsNullOrEmpty(headerOutputDir)) { project.SetClCompileAdditionalIncludeDirectories(headerOutputDir); } else { project.SetClCompileAdditionalIncludeDirectories(outputDir); } } value = project.GetProperty("ProjectTypeGuids", false); if (!string.IsNullOrEmpty(value)) { value = value.Replace(Package.IceBuilderOldFlavor, Package.IceBuilderNewFlavor); project.SetProperty("ProjectTypeGuids", value, ""); modified = true; } return(modified); }
public void SetPropertyWithNoChangesShouldNotDirty() { Project project = new Project(); project.SetProperty("p", "v1"); Assert.Equal(true, project.IsDirty); project.ReevaluateIfNecessary(); project.SetProperty("p", "v1"); Assert.Equal(false, project.IsDirty); }
public void ExternallyMarkDirty() { Project project = new Project(); project.SetProperty("p", "v"); project.ReevaluateIfNecessary(); Assert.Equal(false, project.IsDirty); ProjectProperty property1 = project.GetProperty("p"); project.MarkDirty(); Assert.Equal(true, project.IsDirty); project.ReevaluateIfNecessary(); Assert.Equal(false, project.IsDirty); ProjectProperty property2 = project.GetProperty("p"); Assert.Equal(false, Object.ReferenceEquals(property1, property2)); // different object indicates reevaluation occurred }
public static void Publish(EnvDTE.Project project, Dictionary <string, string> buildProperties, Microsoft.Build.Framework.LoggerVerbosity verbosity) { if (project == null) { throw new ArgumentNullException("project"); } if (buildProperties == null) { throw new ArgumentNullException("buildProperties"); } System.Threading.Tasks.Task.Factory.StartNew(() => { DTE dte = (DTE)CloudFoundryVisualStudioPackage.GetGlobalService(typeof(DTE)); var window = dte.Windows.Item(EnvDTE.Constants.vsWindowKindOutput); var output = (OutputWindow)window.Object; OutputWindowPane pane = null; pane = output.OutputWindowPanes.Cast <OutputWindowPane>().FirstOrDefault(x => x.Name == "Publish"); if (pane == null) { pane = output.OutputWindowPanes.Add("Publish"); } var showOutputWindowPropertyValue = VsUtils.GetVisualStudioSetting("Environment", "ProjectsAndSolution", "ShowOutputWindowBeforeBuild"); if (showOutputWindowPropertyValue != null) { if ((bool)showOutputWindowPropertyValue == true) { window.Visible = true; } } pane.Activate(); ErrorListProvider errorList = CloudFoundryVisualStudioPackage.GetErrorListPane; if (errorList == null) { throw new InvalidOperationException("Could not retrieve error list provider"); } errorList.Tasks.Clear(); MSBuildLogger customLogger = new MSBuildLogger(pane, errorList); customLogger.Verbosity = verbosity; pane.Clear(); pane.OutputString("Starting push..."); Microsoft.Build.Evaluation.Project websiteProject = null; using (var buildManager = new BuildManager()) { using (var projectCollection = new ProjectCollection()) { string proj = project.FullName; if (project.Object is VsWebSite.VSWebSite) { string projectDir = new System.IO.DirectoryInfo(System.IO.Path.GetDirectoryName(buildProperties["PublishProfile"])).Parent.Parent.FullName; proj = Path.Combine(projectDir, CloudFoundry.VisualStudio.ProjectPush.PushEnvironment.DefaultWebsiteProjectName); } websiteProject = projectCollection.LoadProject(proj); foreach (KeyValuePair <string, string> parameter in buildProperties) { websiteProject.SetProperty(parameter.Key, parameter.Value); } BuildParameters buildParameters = new BuildParameters(projectCollection); buildParameters.Loggers = new List <ILogger>() { customLogger }; BuildRequestData buildRequestData = new BuildRequestData(websiteProject.CreateProjectInstance(), new string[] { }); buildManager.Build(buildParameters, buildRequestData); if (errorList.Tasks.Count > 0) { errorList.BringToFront(); } pane.OutputString("Push operation finished!"); projectCollection.UnregisterAllLoggers(); } } }); }
public void SetPropertyWithItemExpression() { Project project = new Project(); project.AddItem("i", "i1"); project.SetProperty("p1", "x@(i)x%(m)x"); Assert.Equal("x@(i)x%(m)x", project.GetPropertyValue("p1")); }
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> /// Sets the value of the property. /// </summary> /// <param name="value">Property value to set.</param> /// <param name="configs">Optional list of configurations to set the property in; /// defaults to the project current configuration</param> /// <remarks> /// Before calling this method, the caller must ensure that the value is valid according to /// the <see cref="PropertyValidator"/> class, and that the project file is writable. /// In most cases the caller should also ensure that the new value is different from the /// existing value, to avoid dirtying the project file unnecessarily. /// </remarks> public void SetValue(string value, IList <ProjectConfig> configs) { WixHelperMethods.VerifyNonNullArgument(value, "value"); value = value.Trim(); MSBuild.Project buildProject = this.project.BuildProject; if (this.PerUser) { if (this.project.UserBuildProject == null) { this.project.CreateUserBuildProject(); } buildProject = this.project.UserBuildProject; } value = this.Escape(value); if (this.PerConfig) { if (configs == null || configs.Count == 0) { configs = new ProjectConfig[] { this.project.CurrentConfig }; } foreach (ProjectConfig config in configs) { bool set = false; // First see if there's an existing property group that matches our condition foreach (ProjectPropertyGroupElement propGroup in buildProject.Xml.PropertyGroups) { // if there is, set it within that group if (String.Equals(propGroup.Condition, config.Condition, StringComparison.Ordinal)) { propGroup.SetProperty(this.propertyName, value); set = true; break; } } // If not, add a new property group for the condition and set the property within it if (!set) { ProjectPropertyGroupElement newPropGroup = buildProject.Xml.AddPropertyGroup(); newPropGroup.Condition = config.Condition; newPropGroup.SetProperty(this.propertyName, value); set = true; } buildProject.ReevaluateIfNecessary(); } } else { if (this.EndOfProjectFile) { List <ProjectPropertyGroupElement> propertyGroupsToDelete = new List <ProjectPropertyGroupElement>(); // First see if there's an existing property group with our property foreach (ProjectPropertyGroupElement propGroup in buildProject.Xml.PropertyGroups) { List <ProjectPropertyElement> propertiesToDelete = new List <ProjectPropertyElement>(); if (!String.IsNullOrEmpty(propGroup.Condition)) { continue; } foreach (ProjectPropertyElement property in propGroup.Properties) { // if there is, remove it so the new value is at the end of the file if (String.IsNullOrEmpty(property.Condition) && String.Equals(property.Name, this.propertyName, StringComparison.OrdinalIgnoreCase)) { propertiesToDelete.Add(property); } } foreach (ProjectPropertyElement property in propertiesToDelete) { propGroup.RemoveChild(property); } if (propGroup.Count == 0) { propertyGroupsToDelete.Add(propGroup); } } foreach (ProjectPropertyGroupElement propGroup in propertyGroupsToDelete) { buildProject.Xml.RemoveChild(propGroup); } ProjectPropertyGroupElement newPropGroup = buildProject.Xml.CreatePropertyGroupElement(); buildProject.Xml.AppendChild(newPropGroup); newPropGroup.SetProperty(this.propertyName, value); } else { buildProject.SetProperty(this.propertyName, value); } } this.project.InvalidatePropertyCache(); this.project.SetProjectFileDirty(true); }
public override void Generate(ProjectType projectType, MSBuild.Project project) { project.SetProperty(Name, Value); }
public void SetValueWithPropertyExpression() { Project project = new Project(); project.SetProperty("p", "p0"); ProjectItem item = project.AddItem("i", "i1")[0]; ProjectMetadata metadatum = item.SetMetadataValue("m", "m1"); project.ReevaluateIfNecessary(); metadatum.UnevaluatedValue = "$(p)"; Assert.AreEqual("$(p)", metadatum.UnevaluatedValue); Assert.AreEqual("p0", metadatum.EvaluatedValue); }
public void SetPropertyAfterRemoved2() { Assert.Throws<InvalidOperationException>(() => { Project project = new Project(); var property = project.SetProperty("p", "v1"); property.Xml.Parent.Parent.RemoveAllChildren(); property.UnevaluatedValue = "v2"; } ); }
public void ReevaluationCounter() { Project project = new Project(); int last = project.EvaluationCounter; project.ReevaluateIfNecessary(); Assert.Equal(project.EvaluationCounter, last); last = project.EvaluationCounter; project.SetProperty("p", "v"); project.ReevaluateIfNecessary(); Assert.NotEqual(project.EvaluationCounter, last); }
public void SetNewPropertyAfterEquivalentsParentRemoved() { Project project = new Project(); var property = project.SetProperty("p", "v1"); property.Xml.Parent.Parent.RemoveAllChildren(); project.SetProperty("p", "v2"); Assert.Equal(1, project.Xml.Properties.Count()); project.ReevaluateIfNecessary(); Assert.Equal("v2", project.GetPropertyValue("p")); }
public void ChangeGlobalPropertyAfterReevaluation2() { Assert.Throws<InvalidOperationException>(() => { Project project = new Project(); project.SetGlobalProperty("p", "v1"); project.ReevaluateIfNecessary(); project.SetProperty("p", "v2"); } ); }
public void RemoveProperty() { Project project = new Project(); int environmentPropertyCount = Helpers.MakeList(project.Properties).Count; project.SetProperty("p1", "v1"); project.ReevaluateIfNecessary(); project.RemoveProperty(project.GetProperty("p1")); string expected = ObjectModelHelpers.CleanupFileContents(@"<Project ToolsVersion=""msbuilddefaulttoolsversion"" xmlns=""msbuildnamespace"" />"); Helpers.VerifyAssertProjectContent(expected, project.Xml); Assert.Equal(null, project.GetProperty("p1")); ProjectInstance instance = project.CreateProjectInstance(); Assert.Equal(String.Empty, instance.GetPropertyValue("p1")); Assert.Equal(0, Helpers.Count(project.Properties) - environmentPropertyCount); }
public void SetReservedPropertyThroughProject() { Assert.Throws<InvalidOperationException>(() => { Project project = new Project(); project.SetProperty("msbuildprojectdirectory", "v1"); } ); }
public void RemovePropertyWithSibling() { Project project = new Project(); project.SetProperty("p1", "v1"); project.SetProperty("p2", "v2"); project.ReevaluateIfNecessary(); project.RemoveProperty(project.GetProperty("p1")); string expected = ObjectModelHelpers.CleanupFileContents( @"<Project ToolsVersion=""msbuilddefaulttoolsversion"" xmlns=""msbuildnamespace""> <PropertyGroup> <p2>v2</p2> </PropertyGroup> </Project>"); Helpers.VerifyAssertProjectContent(expected, project.Xml); }
public void TestRunPythonCommand() { var expectedSearchPath = string.Format("['{0}', '{1}']", TestData.GetPath(@"TestData").Replace("\\", "\\\\"), TestData.GetPath(@"TestData\HelloWorld").Replace("\\", "\\\\") ); var proj = new Project(TestData.GetPath(@"TestData\Targets\Commands4.pyproj")); foreach (var version in PythonPaths.Versions) { var verStr = version.Version.ToVersion().ToString(); proj.SetProperty("InterpreterId", version.Id.ToString("B")); proj.SetProperty("InterpreterVersion", verStr); proj.RemoveItems(proj.ItemsIgnoringCondition.Where(i => i.ItemType == "InterpreterReference").ToArray()); proj.AddItem("InterpreterReference", string.Format("{0:B}\\{1}", version.Id, verStr)); proj.Save(); proj.ReevaluateIfNecessary(); var log = new StringLogger(LoggerVerbosity.Minimal); Assert.IsTrue(proj.Build("CheckCode", new ILogger[] { new ConsoleLogger(LoggerVerbosity.Detailed), log })); Console.WriteLine(); Console.WriteLine("Output from {0:B} {1}", version.Id, version.Version.ToVersion()); foreach (var line in log.Lines) { Console.WriteLine("* {0}", line.TrimEnd('\r', '\n')); } var logLines = log.Lines.Last().Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); Assert.AreEqual(2, logLines.Length); Assert.AreEqual(version.Version.ToVersion().ToString(), logLines[0].Trim()); Assert.AreEqual(expectedSearchPath, logLines[1].Trim()); } }
static internal void MakeTemplateReplacements(bool isAProject, bool creatingProject, string rootNamespace, string sourceFileName, _BE.Project proj) { if (isAProject) { if (!string.IsNullOrEmpty(rootNamespace)) { _BE.ProjectProperty prop; string name; name = "StartupObject"; prop = proj.GetProperty(name); if (prop != null) { proj.SetProperty(name, prop.UnevaluatedValue.Replace(rootNamespace + ".", "$safeprojectname$.")); } name = "DocumentationFile"; prop = proj.GetProperty(name); if (prop != null) { proj.SetProperty(name, prop.UnevaluatedValue.Replace(rootNamespace + ".", "$safeprojectname$.")); } name = "RootNamespace"; prop = proj.GetProperty(name); if (prop != null) { proj.SetProperty(name, prop.UnevaluatedValue.Replace(rootNamespace, "$safeprojectname$")); } name = "AssemblyName"; prop = proj.GetProperty(name); if (prop != null) { proj.SetProperty(name, prop.UnevaluatedValue.Replace(rootNamespace, "$safeprojectname$")); } } } else { if (creatingProject == true) { //Exporting the entire project ... replace projectname only; this may not work as desired for Web projects, //we don't have any so we don't care. WordReplace(proj, rootNamespace, "$safeprojectname$"); } else { //Exporting a single item from a project. Replace root name space (if given) //and item name if (!string.IsNullOrEmpty(rootNamespace)) { WordReplace(proj, rootNamespace, "$rootnamespace$"); } string itemName = Path.GetFileNameWithoutExtension(sourceFileName); int iDotIndex = itemName.LastIndexOf("."); if (iDotIndex != -1) { //This is intended to fix the foo.designer.vb case (GetFileNameWithoutExtension() //returns foo.designer, and we want to replace just foo itemName = itemName.Substring(0, iDotIndex); } WordReplace(proj, itemName, "$safeitemname$"); } } }
private IEnumerable<string> ResolveAssemblyReferences(Project project) { var projectInstance = project.CreateProjectInstance(); projectInstance.SetProperty("BuildingProject", "false"); project.SetProperty("DesignTimeBuild", "true"); projectInstance.Build("ResolveAssemblyReferences", new[] { new ConsoleLogger(LoggerVerbosity.Minimal) }); var items = projectInstance.GetItems("_ResolveAssemblyReferenceResolvedFiles"); var baseDirectory = Path.GetDirectoryName(this.FileName); return items.Select(i => Path.Combine(baseDirectory, i.GetMetadataValue("Identity"))); }
public void SetPropertyWithPropertyExpression() { Project project = new Project(); project.SetProperty("p0", "v0"); project.SetProperty("p1", "$(p0)"); Assert.Equal("v0", project.GetPropertyValue("p1")); }