本文整理汇总了C#中Microsoft.Build.Evaluation.ProjectCollection.GetToolset方法的典型用法代码示例。如果您正苦于以下问题:C# ProjectCollection.GetToolset方法的具体用法?C# ProjectCollection.GetToolset怎么用?C# ProjectCollection.GetToolset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Build.Evaluation.ProjectCollection
的用法示例。
在下文中一共展示了ProjectCollection.GetToolset方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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
}
}
示例2: foreach
//.........这里部分代码省略.........
break;
}
}
}
}
projectCollection = new ProjectCollection
(
globalProperties,
loggers,
null,
Microsoft.Build.Evaluation.ToolsetDefinitionLocations.ConfigurationFile | Microsoft.Build.Evaluation.ToolsetDefinitionLocations.Registry,
cpuCount,
onlyLogCriticalEvents
);
if (debugger)
{
// Debugging is not currently fully supported so we don't want to open
// public API for it. Also, we want to have a way to make it work when running inside VS.
// So use an environment variable. The undocumented /debug switch is just an easy way to set it.
Environment.SetEnvironmentVariable("MSBUILDDEBUGGING", "1");
}
if (toolsVersion != null && !projectCollection.ContainsToolset(toolsVersion))
{
ThrowInvalidToolsVersionInitializationException(projectCollection.Toolsets, toolsVersion);
}
// If the user has requested that the schema be validated, do that here.
if (needToValidateProject && !FileUtilities.IsSolutionFilename(projectFile))
{
Microsoft.Build.Evaluation.Project project = projectCollection.LoadProject(projectFile, globalProperties, toolsVersion);
Microsoft.Build.Evaluation.Toolset toolset = projectCollection.GetToolset((toolsVersion == null) ? project.ToolsVersion : toolsVersion);
if (toolset == null)
{
ThrowInvalidToolsVersionInitializationException(projectCollection.Toolsets, project.ToolsVersion);
}
ProjectSchemaValidationHandler.VerifyProjectSchema(projectFile, schemaFile, toolset.ToolsPath);
// If there are schema validation errors, an InitializationException is thrown, so if we get here,
// we can safely assume that the project successfully validated.
projectCollection.UnloadProject(project);
}
if (preprocessWriter != null && !FileUtilities.IsSolutionFilename(projectFile))
{
Project project = projectCollection.LoadProject(projectFile, globalProperties, toolsVersion);
project.SaveLogicalProject(preprocessWriter);
projectCollection.UnloadProject(project);
success = true;
}
else
{
BuildRequestData request = new BuildRequestData(projectFile, globalProperties, toolsVersion, targets, null);
BuildParameters parameters = new BuildParameters(projectCollection);
// By default we log synchronously to the console for compatibility with previous versions,
// but it is slightly slower
if (!String.Equals(Environment.GetEnvironmentVariable("MSBUILDLOGASYNC"), "1", StringComparison.Ordinal))
{
示例3: TestGenerateSubToolsetVersion_ExplicitlyPassedGlobalPropertyWins
public void TestGenerateSubToolsetVersion_ExplicitlyPassedGlobalPropertyWins()
{
string originalVisualStudioVersion = Environment.GetEnvironmentVariable("VisualStudioVersion");
try
{
Environment.SetEnvironmentVariable("VisualStudioVersion", ObjectModelHelpers.CurrentVisualStudioVersion);
IDictionary<string, string> globalProperties = new Dictionary<string, string>();
globalProperties.Add("VisualStudioVersion", "v13.0");
ProjectCollection projectCollection = new ProjectCollection(globalProperties);
Toolset parentToolset = projectCollection.GetToolset("4.0");
Toolset t = new Toolset("Fake", parentToolset.ToolsPath, null, projectCollection, null, parentToolset.OverrideTasksPath);
IDictionary<string, string> explicitGlobalProperties = new Dictionary<string, string>();
explicitGlobalProperties.Add("VisualStudioVersion", "FakeSubToolset");
Assert.Equal("FakeSubToolset", t.GenerateSubToolsetVersion(explicitGlobalProperties, 0));
}
finally
{
Environment.SetEnvironmentVariable("VisualStudioVersion", originalVisualStudioVersion);
}
}
示例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: TestNoSubToolset_GlobalPropertyOverrides
public void TestNoSubToolset_GlobalPropertyOverrides()
{
string originalVisualStudioVersion = Environment.GetEnvironmentVariable("VisualStudioVersion");
try
{
Environment.SetEnvironmentVariable("VisualStudioVersion", null);
IDictionary<string, string> globalProperties = new Dictionary<string, string>();
globalProperties.Add("VisualStudioVersion", "99.0");
ProjectCollection projectCollection = new ProjectCollection(globalProperties);
Toolset parentToolset = projectCollection.GetToolset("4.0");
Toolset t = new Toolset("Fake", parentToolset.ToolsPath, null, projectCollection, null, parentToolset.OverrideTasksPath);
Assert.Equal("99.0", t.GenerateSubToolsetVersion());
}
finally
{
Environment.SetEnvironmentVariable("VisualStudioVersion", originalVisualStudioVersion);
}
}
示例6: TestNoSubToolset_EnvironmentOverrides
public void TestNoSubToolset_EnvironmentOverrides()
{
string originalVisualStudioVersion = Environment.GetEnvironmentVariable("VisualStudioVersion");
try
{
Environment.SetEnvironmentVariable("VisualStudioVersion", "foo");
ProjectCollection projectCollection = new ProjectCollection();
Toolset parentToolset = projectCollection.GetToolset("4.0");
Toolset t = new Toolset("Fake", parentToolset.ToolsPath, null, projectCollection, null, parentToolset.OverrideTasksPath);
Assert.Equal("foo", t.GenerateSubToolsetVersion());
}
finally
{
Environment.SetEnvironmentVariable("VisualStudioVersion", originalVisualStudioVersion);
}
}
示例7: TestGenerateSubToolsetVersionWhenNoSubToolset
public void TestGenerateSubToolsetVersionWhenNoSubToolset()
{
string originalVisualStudioVersion = Environment.GetEnvironmentVariable("VisualStudioVersion");
try
{
Environment.SetEnvironmentVariable("VisualStudioVersion", null);
ProjectCollection projectCollection = new ProjectCollection();
Toolset parentToolset = projectCollection.GetToolset("4.0");
Toolset t = new Toolset("Fake", parentToolset.ToolsPath, null, projectCollection, null, parentToolset.OverrideTasksPath);
string subToolsetVersion = t.GenerateSubToolsetVersion();
if (Toolset.Dev10IsInstalled)
{
Assert.Equal(Constants.Dev10SubToolsetValue, subToolsetVersion);
}
else
{
Assert.Null(subToolsetVersion);
}
}
finally
{
Environment.SetEnvironmentVariable("VisualStudioVersion", originalVisualStudioVersion);
}
}
示例8: Execute
public void Execute ()
{
bool result = false;
bool show_stacktrace = false;
try {
parameters.ParseArguments (args);
show_stacktrace = (parameters.LoggerVerbosity == LoggerVerbosity.Detailed ||
parameters.LoggerVerbosity == LoggerVerbosity.Diagnostic);
if (!parameters.NoLogo)
ErrorUtilities.ShowVersion (false);
project_collection = new ProjectCollection ();
if (!String.IsNullOrEmpty (parameters.ToolsVersion)) {
if (project_collection.GetToolset (parameters.ToolsVersion) == null)
ErrorUtilities.ReportError (0, new InvalidToolsetDefinitionException ("Toolset " + parameters.ToolsVersion + " was not found").Message);
project_collection.DefaultToolsVersion = parameters.ToolsVersion;
}
foreach (var p in parameters.Properties)
project_collection.GlobalProperties.Add (p.Key, p.Value);
if (!parameters.NoConsoleLogger) {
printer = new ConsoleReportPrinter ();
ConsoleLogger cl = new ConsoleLogger (parameters.LoggerVerbosity,
printer.Print, printer.SetForeground, printer.ResetColor);
cl.Parameters = parameters.ConsoleLoggerParameters;
cl.Verbosity = parameters.LoggerVerbosity;
project_collection.RegisterLogger (cl);
}
if (parameters.FileLoggerParameters != null) {
for (int i = 0; i < parameters.FileLoggerParameters.Length; i ++) {
string fl_params = parameters.FileLoggerParameters [i];
if (fl_params == null)
continue;
var fl = new FileLogger ();
if (fl_params.Length == 0 && i > 0)
fl.Parameters = String.Format ("LogFile=msbuild{0}.log", i);
else
fl.Parameters = fl_params;
project_collection.RegisterLogger (fl);
}
}
foreach (LoggerInfo li in parameters.Loggers) {
Assembly assembly;
if (li.InfoType == LoadInfoType.AssemblyFilename)
assembly = Assembly.LoadFrom (li.Filename);
else
assembly = Assembly.Load (li.AssemblyName);
ILogger logger = (ILogger)Activator.CreateInstance (assembly.GetType (li.ClassName));
logger.Parameters = li.Parameters;
project_collection.RegisterLogger (logger);
}
string projectFile = parameters.ProjectFile;
if (!File.Exists (projectFile)) {
ErrorUtilities.ReportError (0, String.Format ("Project file '{0}' not found.", projectFile));
return;
}
XmlReaderSettings settings = new XmlReaderSettings ();
if (parameters.Validate) {
settings.ValidationType = ValidationType.Schema;
if (parameters.ValidationSchema == null)
using (var xsdxml = XmlReader.Create (defaultSchema))
settings.Schemas.Add (XmlSchema.Read (xsdxml, null));
else
using (var xsdxml = XmlReader.Create (parameters.ValidationSchema))
settings.Schemas.Add (XmlSchema.Read (xsdxml, null));
}
var projectInstances = new List<ProjectInstance> ();
if (string.Equals (Path.GetExtension (projectFile), ".sln", StringComparison.OrdinalIgnoreCase)) {
var parser = new SolutionParser ();
var root = ProjectRootElement.Create (project_collection);
root.FullPath = projectFile;
parser.ParseSolution (projectFile, project_collection, root, LogWarning);
projectInstances.Add (new Project (root, parameters.Properties, parameters.ToolsVersion, project_collection).CreateProjectInstance ());
} else {
project = ProjectRootElement.Create (XmlReader.Create (projectFile, settings), project_collection);
project.FullPath = projectFile;
var pi = new ProjectInstance (project, parameters.Properties, parameters.ToolsVersion, project_collection);
projectInstances.Add (pi);
}
foreach (var projectInstance in projectInstances) {
var targets = parameters.Targets.Length > 0 ? parameters.Targets : projectInstance.DefaultTargets.ToArray ();
result = projectInstance.Build (targets, parameters.Loggers.Count > 0 ? parameters.Loggers : project_collection.Loggers);
if (!result)
break;
}
}
catch (InvalidProjectFileException ipfe) {
ErrorUtilities.ReportError (0, show_stacktrace ? ipfe.ToString () : ipfe.Message);
//.........这里部分代码省略.........
示例9: 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]);
}
示例10: 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));
}
示例11: 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]);
}