本文整理汇总了C#中Microsoft.Build.Evaluation.ProjectCollection.SetGlobalProperty方法的典型用法代码示例。如果您正苦于以下问题:C# ProjectCollection.SetGlobalProperty方法的具体用法?C# ProjectCollection.SetGlobalProperty怎么用?C# ProjectCollection.SetGlobalProperty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Build.Evaluation.ProjectCollection
的用法示例。
在下文中一共展示了ProjectCollection.SetGlobalProperty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProjectBuilder
public ProjectBuilder (string file, string binDir)
{
this.file = file;
RunSTA (delegate
{
engine = new ProjectCollection ();
engine.SetGlobalProperty ("BuildingInsideVisualStudio", "true");
//we don't have host compilers in MD, and this is set to true by some of the MS targets
//which causes it to always run the CoreCompile task if BuildingInsideVisualStudio is also
//true, because the VS in-process compiler would take care of the deps tracking
engine.SetGlobalProperty ("UseHostCompilerIfAvailable", "false");
consoleLogger = new ConsoleLogger (LoggerVerbosity.Normal, LogWriteLine, null, null);
engine.RegisterLogger (consoleLogger);
});
Refresh ();
}
示例2: BuildProject
/// <summary>
/// Builds a project (.csproj, .vbproj, etc)
/// </summary>
/// <param name="projectFileName">Physical path to project file</param>
/// <param name="configuration">Configuration to build in (usually "Debug" or "Release")</param>
/// <param name="logFilePath">Physical path to write a build log file to</param>
/// <param name="targets">The build target(s) to build. Usually "Build," "Rebuild," "Clean," etc</param>
/// <returns>True if the project compiled successfully</returns>
public static bool BuildProject(string projectFileName, string configuration, string logFilePath, string[] targets)
{
var projects = new ProjectCollection(ToolsetDefinitionLocations.Registry);
var logger = new FileLogger();
logger.Parameters = @"logfile=" + logFilePath;
projects.RegisterLogger(logger);
projects.DefaultToolsVersion = "4.0";
projects.SetGlobalProperty("Configuration", configuration);
return projects.LoadProject(projectFileName).Build(targets);
}
示例3: GetEngine
ProjectCollection GetEngine (string binDir)
{
ProjectCollection engine = null;
RunSTA (delegate {
if (!engines.TryGetValue (binDir, out engine)) {
engine = new ProjectCollection ();
engine.SetGlobalProperty ("BuildingInsideVisualStudio", "true");
//we don't have host compilers in MD, and this is set to true by some of the MS targets
//which causes it to always run the CoreCompile task if BuildingInsideVisualStudio is also
//true, because the VS in-process compiler would take care of the deps tracking
engine.SetGlobalProperty ("UseHostCompilerIfAvailable", "false");
engines [binDir] = engine;
}
});
return engine;
}
示例4: InitializeEngine
static ProjectCollection InitializeEngine (string slnFile)
{
var engine = new ProjectCollection ();
engine.DefaultToolsVersion = MSBuildConsts.Version;
//this causes build targets to behave how they should inside an IDE, instead of in a command-line process
engine.SetGlobalProperty ("BuildingInsideVisualStudio", "true");
//we don't have host compilers in MD, and this is set to true by some of the MS targets
//which causes it to always run the CoreCompile task if BuildingInsideVisualStudio is also
//true, because the VS in-process compiler would take care of the deps tracking
engine.SetGlobalProperty ("UseHostCompilerIfAvailable", "false");
if (string.IsNullOrEmpty (slnFile))
return engine;
engine.SetGlobalProperty ("SolutionPath", Path.GetFullPath (slnFile));
engine.SetGlobalProperty ("SolutionName", Path.GetFileNameWithoutExtension (slnFile));
engine.SetGlobalProperty ("SolutionFilename", Path.GetFileName (slnFile));
engine.SetGlobalProperty ("SolutionDir", Path.GetDirectoryName (slnFile) + Path.DirectorySeparatorChar);
return engine;
}
示例5: RemovingGlobalPropertiesOnCollectionUpdatesProjects2
public void RemovingGlobalPropertiesOnCollectionUpdatesProjects2()
{
ProjectCollection collection = new ProjectCollection();
collection.SetGlobalProperty("g1", "v1");
Project project1 = new Project(collection);
project1.FullPath = "c:\\y"; // load into collection
project1.SetGlobalProperty("g1", "v0"); // mask collection property
Helpers.ClearDirtyFlag(project1.Xml);
collection.RemoveGlobalProperty("g1"); // should modify the project
Assert.Equal(0, project1.GlobalProperties.Count);
Assert.Equal(true, project1.IsDirty);
}
示例6: RemovingGlobalPropertiesOnCollectionUpdatesProjects
public void RemovingGlobalPropertiesOnCollectionUpdatesProjects()
{
ProjectCollection collection = new ProjectCollection();
Project project1 = new Project(collection);
project1.FullPath = "c:\\y"; // load into collection
Assert.Equal(0, project1.GlobalProperties.Count);
Helpers.ClearDirtyFlag(project1.Xml);
collection.SetGlobalProperty("g1", "v1"); // should make both dirty
collection.SetGlobalProperty("g2", "v2"); // should make both dirty
Assert.Equal(true, project1.IsDirty);
Project project2 = new Project(collection);
project2.FullPath = "c:\\x"; // load into collection
Assert.Equal(true, project2.IsDirty);
Assert.Equal(2, project1.GlobalProperties.Count);
Assert.Equal("v1", project2.GlobalProperties["g1"]);
Assert.Equal(2, project2.GlobalProperties.Count);
Assert.Equal("v1", project2.GlobalProperties["g1"]);
Helpers.ClearDirtyFlag(project1.Xml);
Helpers.ClearDirtyFlag(project2.Xml);
collection.RemoveGlobalProperty("g2"); // should make both dirty
Assert.Equal(true, project1.IsDirty);
Assert.Equal(true, project2.IsDirty);
Assert.Equal(1, project1.GlobalProperties.Count);
Assert.Equal(1, project2.GlobalProperties.Count);
collection.RemoveGlobalProperty("g1");
Assert.Equal(0, project1.GlobalProperties.Count);
Assert.Equal(0, project2.GlobalProperties.Count);
}
示例7: SettingGlobalPropertiesOnCollectionUpdatesProjects2
public void SettingGlobalPropertiesOnCollectionUpdatesProjects2()
{
ProjectCollection collection = new ProjectCollection();
Project project1 = new Project(collection);
project1.FullPath = "c:\\y"; // load into collection
project1.SetGlobalProperty("g1", "v0");
Helpers.ClearDirtyFlag(project1.Xml);
collection.SetGlobalProperty("g1", "v1");
collection.SetGlobalProperty("g2", "v2");
Assert.Equal(2, project1.GlobalProperties.Count);
Assert.Equal("v1", project1.GlobalProperties["g1"]);
Assert.Equal("v2", project1.GlobalProperties["g2"]); // Got overwritten
Assert.Equal(true, project1.IsDirty);
}
示例8: SettingGlobalPropertiesOnCollectionUpdatesProjects
public void SettingGlobalPropertiesOnCollectionUpdatesProjects()
{
ProjectCollection collection = new ProjectCollection();
Project project1 = new Project(collection);
project1.FullPath = "c:\\y"; // load into collection
Assert.Equal(0, project1.GlobalProperties.Count);
collection.SetGlobalProperty("g1", "v1");
collection.SetGlobalProperty("g2", "v2");
collection.SetGlobalProperty("g2", "v2"); // try dupe
Assert.Equal(2, project1.GlobalProperties.Count);
collection.RemoveGlobalProperty("g2");
Project project2 = new Project(collection);
project2.FullPath = "c:\\x"; // load into collection
Assert.Equal(1, project1.GlobalProperties.Count);
Assert.Equal("v1", project2.GlobalProperties["g1"]);
Assert.Equal(1, project2.GlobalProperties.Count);
Assert.Equal("v1", project2.GlobalProperties["g1"]);
}
示例9: ProjectCollectionChangedEvent
public void ProjectCollectionChangedEvent()
{
ProjectCollection collection = new ProjectCollection();
bool dirtyRaised = false;
ProjectCollectionChangedState expectedChange = ProjectCollectionChangedState.Loggers;
collection.ProjectCollectionChanged +=
(sender, e) =>
{
Assert.Same(collection, sender);
Assert.Equal(expectedChange, e.Changed);
dirtyRaised = true;
};
Assert.False(dirtyRaised);
expectedChange = ProjectCollectionChangedState.DisableMarkDirty;
dirtyRaised = false;
collection.DisableMarkDirty = true; // LEAVE THIS TRUE for rest of the test, to verify it doesn't suppress these events
Assert.True(dirtyRaised);
expectedChange = ProjectCollectionChangedState.IsBuildEnabled;
dirtyRaised = false;
collection.IsBuildEnabled = !collection.IsBuildEnabled;
Assert.True(dirtyRaised);
expectedChange = ProjectCollectionChangedState.OnlyLogCriticalEvents;
dirtyRaised = false;
collection.OnlyLogCriticalEvents = !collection.OnlyLogCriticalEvents;
Assert.True(dirtyRaised);
expectedChange = ProjectCollectionChangedState.SkipEvaluation;
dirtyRaised = false;
collection.SkipEvaluation = !collection.SkipEvaluation;
Assert.True(dirtyRaised);
expectedChange = ProjectCollectionChangedState.GlobalProperties;
dirtyRaised = false;
collection.SetGlobalProperty("a", "b");
Assert.True(dirtyRaised);
expectedChange = ProjectCollectionChangedState.GlobalProperties;
dirtyRaised = false;
collection.RemoveGlobalProperty("a");
Assert.True(dirtyRaised);
// Verify HostServices changes raise the event.
expectedChange = ProjectCollectionChangedState.HostServices;
dirtyRaised = false;
collection.HostServices = new Execution.HostServices();
Assert.True(dirtyRaised);
expectedChange = ProjectCollectionChangedState.Loggers;
dirtyRaised = false;
collection.RegisterLogger(new MockLogger());
Assert.True(dirtyRaised);
expectedChange = ProjectCollectionChangedState.Loggers;
dirtyRaised = false;
collection.RegisterLoggers(new Microsoft.Build.Framework.ILogger[] { new MockLogger(), new MockLogger() });
Assert.True(dirtyRaised);
expectedChange = ProjectCollectionChangedState.Loggers;
dirtyRaised = false;
collection.UnregisterAllLoggers();
Assert.True(dirtyRaised);
expectedChange = ProjectCollectionChangedState.Toolsets;
dirtyRaised = false;
collection.AddToolset(new Toolset("testTools", Path.GetTempPath(), collection, Path.GetTempPath()));
Assert.True(dirtyRaised);
expectedChange = ProjectCollectionChangedState.DefaultToolsVersion;
dirtyRaised = false;
collection.DefaultToolsVersion = "testTools";
Assert.True(dirtyRaised);
expectedChange = ProjectCollectionChangedState.Toolsets;
dirtyRaised = false;
collection.RemoveToolset("testTools");
Assert.True(dirtyRaised);
expectedChange = ProjectCollectionChangedState.Toolsets;
dirtyRaised = false;
collection.RemoveAllToolsets();
Assert.True(dirtyRaised);
}
示例10: GlobalPropertyInheritLoadFromXml2
public void GlobalPropertyInheritLoadFromXml2()
{
XmlReader reader = CreateProjectXmlReader();
ProjectCollection collection = new ProjectCollection();
collection.SetGlobalProperty("p", "v");
Project project = collection.LoadProject(reader, "4.0");
Assert.Equal("v", project.GlobalProperties["p"]);
}
示例11: GlobalPropertyInheritLoadFromFile3
public void GlobalPropertyInheritLoadFromFile3()
{
string path = null;
try
{
path = CreateProjectFile();
ProjectCollection collection = new ProjectCollection();
collection.SetGlobalProperty("p", "v");
Project project = collection.LoadProject(path, null, "4.0");
Assert.Equal("v", project.GlobalProperties["p"]);
}
finally
{
File.Delete(path);
}
}
示例12: VerifyProjectCollectionEvents
/// <summary>
/// Verify that when a property is set on the project collection that the correct events are fired.
/// </summary>
private void VerifyProjectCollectionEvents(ProjectCollection collection, bool expectEventRaised, string propertyValue)
{
bool raisedEvent = false;
ProjectCollectionChangedState expectedChange = ProjectCollectionChangedState.Loggers;
collection.ProjectCollectionChanged +=
(sender, e) =>
{
Assert.Same(collection, sender);
Assert.Equal(expectedChange, e.Changed);
raisedEvent = true;
};
expectedChange = ProjectCollectionChangedState.GlobalProperties;
collection.SetGlobalProperty("a", propertyValue);
Assert.Equal(raisedEvent, expectEventRaised);
ProjectPropertyInstance property = collection.GetGlobalProperty("a");
Assert.NotNull(property);
Assert.True(String.Equals(property.EvaluatedValue, ProjectCollection.Unescape(propertyValue), StringComparison.OrdinalIgnoreCase));
}
示例13: ProjectChangedEvent
public void ProjectChangedEvent()
{
ProjectCollection collection = new ProjectCollection();
ProjectRootElement pre = null;
Project project = null;
bool dirtyRaised = false;
collection.ProjectChanged +=
(sender, e) =>
{
Assert.Same(collection, sender);
Assert.Same(project, e.Project);
dirtyRaised = true;
};
Assert.False(dirtyRaised);
pre = ProjectRootElement.Create(collection);
project = new Project(pre, null, null, collection);
// all these should still pass with disableMarkDirty set
collection.DisableMarkDirty = true;
project.DisableMarkDirty = true;
dirtyRaised = false;
pre.AppendChild(pre.CreatePropertyGroupElement());
Assert.False(dirtyRaised); // "Dirtying the XML directly should not result in a ProjectChanged event."
// No events should be raised before we associate a filename with the PRE
dirtyRaised = false;
project.SetGlobalProperty("someGlobal", "someValue");
Assert.False(dirtyRaised);
dirtyRaised = false;
project.SetProperty("someProp", "someValue");
Assert.False(dirtyRaised);
pre.FullPath = FileUtilities.GetTemporaryFile();
dirtyRaised = false;
project.SetGlobalProperty("someGlobal", "someValue2");
Assert.True(dirtyRaised);
dirtyRaised = false;
project.RemoveGlobalProperty("someGlobal");
Assert.True(dirtyRaised);
dirtyRaised = false;
collection.SetGlobalProperty("somePCglobal", "someValue");
Assert.True(dirtyRaised);
dirtyRaised = false;
project.SetProperty("someProp", "someValue2");
Assert.True(dirtyRaised);
}
示例14: ProjectXmlChangedEvent
public void ProjectXmlChangedEvent()
{
ProjectCollection collection = new ProjectCollection();
ProjectRootElement pre = null;
bool dirtyRaised = false;
collection.ProjectXmlChanged +=
(sender, e) =>
{
Assert.Same(collection, sender);
Assert.Same(pre, e.ProjectXml);
this.TestOutput.WriteLine(e.Reason ?? String.Empty);
dirtyRaised = true;
};
Assert.False(dirtyRaised);
// Ensure that the event is raised even when DisableMarkDirty is set.
collection.DisableMarkDirty = true;
// Create a new PRE but don't change the template.
dirtyRaised = false;
pre = ProjectRootElement.Create(collection);
Assert.False(dirtyRaised);
// Change PRE prior to setting a filename and thus associating the PRE with the ProjectCollection.
dirtyRaised = false;
pre.AppendChild(pre.CreatePropertyGroupElement());
Assert.False(dirtyRaised);
// Associate with the ProjectCollection
dirtyRaised = false;
pre.FullPath = FileUtilities.GetTemporaryFile();
Assert.True(dirtyRaised);
// Now try dirtying again and see that the event is raised this time.
dirtyRaised = false;
pre.AppendChild(pre.CreatePropertyGroupElement());
Assert.True(dirtyRaised);
// Make sure that project collection global properties don't raise this event.
dirtyRaised = false;
collection.SetGlobalProperty("a", "b");
Assert.False(dirtyRaised);
// Change GlobalProperties on a project to see that that doesn't propagate as an XML change.
dirtyRaised = false;
var project = new Project(pre);
project.SetGlobalProperty("q", "s");
Assert.False(dirtyRaised);
// Change XML via the Project to verify the event is raised.
dirtyRaised = false;
project.SetProperty("z", "y");
Assert.True(dirtyRaised);
}
示例15: ProjectCollectionChangedEvent2
public void ProjectCollectionChangedEvent2()
{
// Verify if the project, project collection and the value we are setting in the project collection are all the same
// then the projects value for the property should not change and no event should be fired.
ProjectCollection collection = new ProjectCollection();
XmlReader reader = CreateProjectXmlReader();
Project project = collection.LoadProject(reader, "4.0");
project.SetProperty("a", "1");
collection.SetGlobalProperty("a", "1");
VerifyProjectCollectionEvents(collection, false, "1");
// Verify if the project, project collection and the value we are setting in the project collection are all the same
// then the projects value for the property should not change and no event should be fired.
collection = new ProjectCollection();
reader = CreateProjectXmlReader();
project = collection.LoadProject(reader, "4.0");
project.SetProperty("a", "%28x86%29");
collection.SetGlobalProperty("a", "%28x86%29");
VerifyProjectCollectionEvents(collection, false, "%28x86%29");
// Verify if the project, project collection have the same value but a new value is set in the project collection
// then the projects value for the property should be change and an event should be fired.
collection = new ProjectCollection();
reader = CreateProjectXmlReader();
project = collection.LoadProject(reader, "4.0");
project.SetProperty("a", "1");
collection.SetGlobalProperty("a", "1");
VerifyProjectCollectionEvents(collection, true, "2");
project.GetPropertyValue("a").Equals("2", StringComparison.OrdinalIgnoreCase);
// Verify if the project, project collection have the same value but a new value is set in the project collection
// then the projects value for the property should be change and an event should be fired.
collection = new ProjectCollection();
reader = CreateProjectXmlReader();
project = collection.LoadProject(reader, "4.0");
project.SetProperty("a", "1");
collection.SetGlobalProperty("a", "(x86)");
VerifyProjectCollectionEvents(collection, true, "%28x86%29");
project.GetPropertyValue("a").Equals("%28x86%29", StringComparison.OrdinalIgnoreCase);
// Verify if the project has one value and project collection and the property we are setting on the project collection have the same value
// then the projects value for the property should be change but no event should be fired
collection = new ProjectCollection();
reader = CreateProjectXmlReader();
project = collection.LoadProject(reader, "4.0");
project.SetProperty("a", "2");
collection.SetGlobalProperty("a", "1");
VerifyProjectCollectionEvents(collection, false, "1");
project.GetPropertyValue("a").Equals("1", StringComparison.OrdinalIgnoreCase);
// Verify if the project and the property being set have one value but the project collection has another
// then the projects value for the property should not change and event should be fired
collection = new ProjectCollection();
reader = CreateProjectXmlReader();
project = collection.LoadProject(reader, "4.0");
project.SetProperty("a", "1");
collection.SetGlobalProperty("a", "2");
VerifyProjectCollectionEvents(collection, true, "1");
project.GetPropertyValue("a").Equals("1", StringComparison.OrdinalIgnoreCase);
// item is added to project collection for the first time. Make sure it is added to the project and an event is fired.
collection = new ProjectCollection();
reader = CreateProjectXmlReader();
project = collection.LoadProject(reader, "4.0");
VerifyProjectCollectionEvents(collection, true, "1");
project.GetPropertyValue("a").Equals("1", StringComparison.OrdinalIgnoreCase);
}