本文整理汇总了C#中Microsoft.Build.Evaluation.ProjectCollection.AddToolset方法的典型用法代码示例。如果您正苦于以下问题:C# ProjectCollection.AddToolset方法的具体用法?C# ProjectCollection.AddToolset怎么用?C# ProjectCollection.AddToolset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Build.Evaluation.ProjectCollection
的用法示例。
在下文中一共展示了ProjectCollection.AddToolset方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetDefaultToolsVersion
public void SetDefaultToolsVersion()
{
string oldValue = Environment.GetEnvironmentVariable("MSBUILDLEGACYDEFAULTTOOLSVERSION");
try
{
// In the new world of figuring out the ToolsVersion to use, we completely ignore the default
// ToolsVersion in the ProjectCollection. However, this test explicitly depends on modifying
// that, so we need to turn the new defaulting behavior off in order to verify that this still works.
Environment.SetEnvironmentVariable("MSBUILDLEGACYDEFAULTTOOLSVERSION", "1");
InternalUtilities.RefreshInternalEnvironmentValues();
ProjectCollection collection = new ProjectCollection();
collection.AddToolset(new Toolset("x", @"c:\y", collection, null));
collection.DefaultToolsVersion = "x";
Assert.AreEqual("x", collection.DefaultToolsVersion);
string content = @"
<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003' >
<Target Name='t'/>
</Project>
";
Project project = new Project(XmlReader.Create(new StringReader(content)), null, null, collection);
Assert.AreEqual(project.ToolsVersion, "x");
}
finally
{
Environment.SetEnvironmentVariable("MSBUILDLEGACYDEFAULTTOOLSVERSION", oldValue);
InternalUtilities.RefreshInternalEnvironmentValues();
}
}
示例2: ToolsVersionFromEnvironmentVariable_ProjectInstance
public void ToolsVersionFromEnvironmentVariable_ProjectInstance()
{
string oldDefaultToolsVersion = Environment.GetEnvironmentVariable("MSBUILDDEFAULTTOOLSVERSION");
try
{
Environment.SetEnvironmentVariable("MSBUILDDEFAULTTOOLSVERSION", "foo");
InternalUtilities.RefreshInternalEnvironmentValues();
ProjectCollection p = new ProjectCollection();
p.AddToolset(new Toolset("foo", @"c:\foo", p, @"c:\foo\override"));
MockLogger mockLogger = new MockLogger();
LoggingService service = (LoggingService)LoggingService.CreateLoggingService(LoggerMode.Synchronous, 1);
service.RegisterLogger(mockLogger);
bool success = false;
Project project = new Project(XmlReader.Create(new StringReader(@"<Project ToolsVersion='4.0' xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
<Target Name='Foo'>
</Target>
</Project>")), null /* no global properties */, null /* don't explicitly set the toolsversion */, p);
ProjectInstance pi = new ProjectInstance(project.Xml, null /* no global properties */, null /* don't explicitly set the toolsversion */, p);
success = pi.Build(new ILogger[] { mockLogger });
Assert.IsTrue(success);
mockLogger.AssertLogContains("ToolsVersion=\"4.0\"");
mockLogger.AssertLogContains("ToolsVersion=\"foo\"");
}
finally
{
Environment.SetEnvironmentVariable("MSBUILDDEFAULTTOOLSVERSION", oldDefaultToolsVersion);
InternalUtilities.RefreshInternalEnvironmentValues();
}
}
示例3: CustomToolsVersionIsHonored
public void CustomToolsVersionIsHonored()
{
Environment.SetEnvironmentVariable("MSBUILDTREATALLTOOLSVERSIONSASCURRENT", String.Empty);
try
{
string content = @"<Project ToolsVersion=""14.0"" xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
<Target Name=""a"">
<Message Text=""[$(MSBUILDTOOLSVERSION)]"" />
</Target>
</Project>
";
string projectPath = Path.GetTempFileName();
File.WriteAllText(projectPath, content);
ProjectCollection p = new ProjectCollection();
MockLogger mockLogger = new MockLogger();
LoggingService service = (LoggingService)LoggingService.CreateLoggingService(LoggerMode.Synchronous, 1);
service.RegisterLogger(mockLogger);
Toolset source = p.GetToolset("14.0");
Toolset potato = new Toolset("potato", source.ToolsPath, ProjectCollection.GlobalProjectCollection, source.ToolsPath);
p.AddToolset(potato);
bool success = false;
Project project = p.LoadProject(projectPath, "potato");
success = project.Build(mockLogger);
Assert.IsTrue(success);
mockLogger.AssertLogContains("[potato]");
}
finally
{
// Nothing
}
}
示例4: GetFakeToolset
/// <summary>
/// Creates a standard ProjectCollection and adds a fake toolset with the following contents to it:
///
/// ToolsVersion = Fake
/// Base Properties:
/// a = a1
/// b = b1
///
/// SubToolset "12.0":
/// d = d4
/// e = e5
///
/// SubToolset "v11.0":
/// b = b2
/// c = c2
///
/// SubToolset "FakeSubToolset":
/// a = a3
/// c = c3
///
/// SubToolset "v13.0":
/// f = f6
/// g = g7
/// </summary>
private Toolset GetFakeToolset(IDictionary<string, string> globalPropertiesForProjectCollection)
{
ProjectCollection projectCollection = new ProjectCollection(globalPropertiesForProjectCollection);
IDictionary<string, string> properties = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
properties.Add("a", "a1");
properties.Add("b", "b1");
Dictionary<string, SubToolset> subToolsets = new Dictionary<string, SubToolset>(StringComparer.OrdinalIgnoreCase);
// SubToolset 12.0 properties
PropertyDictionary<ProjectPropertyInstance> subToolset12Properties = new PropertyDictionary<ProjectPropertyInstance>();
subToolset12Properties.Set(ProjectPropertyInstance.Create("d", "d4"));
subToolset12Properties.Set(ProjectPropertyInstance.Create("e", "e5"));
// SubToolset v11.0 properties
PropertyDictionary<ProjectPropertyInstance> subToolset11Properties = new PropertyDictionary<ProjectPropertyInstance>();
subToolset11Properties.Set(ProjectPropertyInstance.Create("b", "b2"));
subToolset11Properties.Set(ProjectPropertyInstance.Create("c", "c2"));
// FakeSubToolset properties
PropertyDictionary<ProjectPropertyInstance> fakeSubToolsetProperties = new PropertyDictionary<ProjectPropertyInstance>();
fakeSubToolsetProperties.Set(ProjectPropertyInstance.Create("a", "a3"));
fakeSubToolsetProperties.Set(ProjectPropertyInstance.Create("c", "c3"));
// SubToolset v13.0 properties
PropertyDictionary<ProjectPropertyInstance> subToolset13Properties = new PropertyDictionary<ProjectPropertyInstance>();
subToolset13Properties.Set(ProjectPropertyInstance.Create("f", "f6"));
subToolset13Properties.Set(ProjectPropertyInstance.Create("g", "g7"));
subToolsets.Add("12.0", new SubToolset("12.0", subToolset12Properties));
subToolsets.Add("v11.0", new SubToolset("v11.0", subToolset11Properties));
subToolsets.Add("FakeSubToolset", new SubToolset("FakeSubToolset", fakeSubToolsetProperties));
subToolsets.Add("v13.0", new SubToolset("v13.0", subToolset13Properties));
Toolset parentToolset = projectCollection.GetToolset("4.0");
Toolset fakeToolset = new Toolset("Fake", parentToolset.ToolsPath, properties, projectCollection, subToolsets, parentToolset.OverrideTasksPath);
projectCollection.AddToolset(fakeToolset);
return fakeToolset;
}
示例5: RemoveToolset
public void RemoveToolset()
{
ProjectCollection collection = new ProjectCollection();
Toolset toolset1 = new Toolset("x", "c:\\y", collection, null);
Toolset toolset2 = new Toolset("y", "c:\\z", collection, null);
int initial = Helpers.MakeList<Toolset>(collection.Toolsets).Count;
collection.AddToolset(toolset1);
collection.AddToolset(toolset2);
Assert.Equal(true, collection.RemoveToolset("x"));
Assert.Equal(false, collection.ContainsToolset("x"));
Assert.Equal(1, Helpers.MakeList<Toolset>(collection.Toolsets).Count - initial);
}
示例6: AddTwoToolsets
public void AddTwoToolsets()
{
ProjectCollection collection = new ProjectCollection();
collection.RemoveAllToolsets();
Toolset toolset1 = new Toolset("x", "c:\\y", collection, null);
Toolset toolset2 = new Toolset("y", "c:\\z", collection, null);
collection.AddToolset(toolset1);
collection.AddToolset(toolset2);
Assert.Equal(toolset1, collection.GetToolset("x"));
Assert.Equal(toolset2, collection.GetToolset("y"));
List<Toolset> toolsets = Helpers.MakeList(collection.Toolsets);
Assert.Equal(2, toolsets.Count);
Assert.Equal(true, toolsets.Contains(toolset1));
Assert.Equal(true, toolsets.Contains(toolset2));
}
示例7: ReplaceToolset
public void ReplaceToolset()
{
ProjectCollection collection = new ProjectCollection();
collection.RemoveAllToolsets();
Toolset toolset1 = new Toolset("x", "c:\\y", collection, null);
Toolset toolset2 = new Toolset("x", "c:\\z", collection, null);
collection.AddToolset(toolset1);
collection.AddToolset(toolset2);
Assert.Equal(toolset2, collection.GetToolset("x"));
List<Toolset> toolsets = Helpers.MakeList(collection.Toolsets);
Assert.Equal(1, toolsets.Count);
Assert.Equal(toolset2, toolsets[0]);
}
示例8: AddToolset
public void AddToolset()
{
ProjectCollection collection = new ProjectCollection();
collection.RemoveAllToolsets();
Toolset toolset = new Toolset("x", "c:\\y", collection, null);
collection.AddToolset(toolset);
Assert.Equal(toolset, collection.GetToolset("x"));
Assert.Equal(true, collection.ContainsToolset("x"));
List<Toolset> toolsets = Helpers.MakeList(collection.Toolsets);
Assert.Equal(1, toolsets.Count);
Assert.Equal(toolset, toolsets[0]);
}
示例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: SetDefaultToolsVersion
public void SetDefaultToolsVersion()
{
ProjectCollection collection = new ProjectCollection();
collection.AddToolset(new Toolset("x", @"c:\y", collection, null));
collection.DefaultToolsVersion = "x";
Assert.Equal("x", collection.DefaultToolsVersion);
string content = ObjectModelHelpers.CleanupFileContents(@"
<Project xmlns='msbuildnamespace' >
<Target Name='t'/>
</Project>
");
Project project = new Project(XmlReader.Create(new StringReader(content)), null, null, collection);
// ... and after all that, we end up defaulting to the current ToolsVersion instead. There's a way
// to turn this behavior (new in Dev12) off, but it requires setting an environment variable and
// clearing some internal state to make sure that the update environment variable is picked up, so
// there's not a good way of doing it from these deliberately public OM only tests.
Assert.Equal(project.ToolsVersion, ObjectModelHelpers.MSBuildDefaultToolsVersion);
}
示例11: VerifyCustomToolSetsPropigated
public void VerifyCustomToolSetsPropigated()
{
string netFrameworkDirectory = ToolLocationHelper.GetPathToDotNetFrameworkReferenceAssemblies(TargetDotNetFrameworkVersion.Version45);
string contents = ObjectModelHelpers.CleanupFileContents(@"
<Project xmlns='msbuildnamespace' ToolsVersion='msbuilddefaulttoolsversion'>
<UsingTask TaskName='VerifyGlobalProjectCollection' TaskFactory='CodeTaskFactory' AssemblyFile='$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll'>
<Task>
<Using Namespace='Microsoft.Build.Evaluation'/>
<Reference Include='$(MSBuildToolsPath)\Microsoft.Build.dll'/>
<Code Type='Method'>
<![CDATA[
public override bool Execute()
{
bool foundToolSet = false;
foreach(Toolset t in ProjectCollection.GlobalProjectCollection.Toolsets)
{
if(t.ToolsVersion.Equals(""CustomToolSet"", StringComparison.OrdinalIgnoreCase))
{
foundToolSet = true;
break;
}
}
Log.LogMessage(MessageImportance.High, ""foundToolset:"" + foundToolSet.ToString());
return foundToolSet;
}
]]>
</Code>
</Task>
</UsingTask>
<Target Name='Build'>
<VerifyGlobalProjectCollection/>
</Target>
</Project>");
string originalMsBuildNoInProcNode = Environment.GetEnvironmentVariable("MSBUILDNOINPROCNODE");
string tempFile = null;
try
{
Environment.SetEnvironmentVariable("MSBUILDNOINPROCNODE", "1");
ProjectCollection projectCollection = new ProjectCollection();
Toolset newToolSet = new Toolset("CustomToolSet", "c:\\SomePath", projectCollection, null);
projectCollection.AddToolset(newToolSet);
Project project = CreateProject(contents, null, projectCollection, false);
tempFile = project.FullPath;
BuildRequestData data = new BuildRequestData(tempFile, new Dictionary<string, string>(), ObjectModelHelpers.MSBuildDefaultToolsVersion, new string[] { }, null);
BuildParameters customParameters = new BuildParameters(projectCollection);
customParameters.Loggers = new ILogger[] { _logger };
BuildResult result = _buildManager.Build(customParameters, data);
Assert.AreEqual(BuildResultCode.Success, result.OverallResult);
}
finally
{
if (File.Exists(tempFile))
{
File.Delete(tempFile);
}
Environment.SetEnvironmentVariable("MSBUILDNOINPROCNODE", originalMsBuildNoInProcNode);
}
}
示例12: ToolsVersionAttributeNotSpecifiedOnProjectElementAndDefaultVersionSpecifiedInRegistry
public void ToolsVersionAttributeNotSpecifiedOnProjectElementAndDefaultVersionSpecifiedInRegistry()
{
string oldValue = Environment.GetEnvironmentVariable("MSBUILDLEGACYDEFAULTTOOLSVERSION");
try
{
// In the new world of figuring out the ToolsVersion to use, we completely ignore the default
// ToolsVersion in the ProjectCollection. However, this test explicitly depends on modifying
// that, so we need to turn the new defaulting behavior off in order to verify that this still works.
Environment.SetEnvironmentVariable("MSBUILDLEGACYDEFAULTTOOLSVERSION", "1");
InternalUtilities.RefreshInternalEnvironmentValues();
ProjectCollection projectCollection = new ProjectCollection();
string msbuildOverrideTasksPath = null;
projectCollection.AddToolset(new Toolset("2.0", "20toolsPath", projectCollection, msbuildOverrideTasksPath));
projectCollection.AddToolset(new Toolset(ObjectModelHelpers.MSBuildDefaultToolsVersion, "120toolsPath", projectCollection, msbuildOverrideTasksPath));
string projectPath = ObjectModelHelpers.CreateFileInTempProjectDirectory("x.proj", @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"" />");
Project project = projectCollection.LoadProject(projectPath);
string defaultExpected = "14.1";
if (FrameworkLocationHelper.PathToDotNetFrameworkV20 == null)
{
defaultExpected = ObjectModelHelpers.MSBuildDefaultToolsVersion;
}
Assert.AreEqual(defaultExpected, project.ToolsVersion);
Assert.AreEqual(defaultExpected, projectCollection.DefaultToolsVersion);
}
finally
{
Environment.SetEnvironmentVariable("MSBUILDLEGACYDEFAULTTOOLSVERSION", oldValue);
InternalUtilities.RefreshInternalEnvironmentValues();
}
}