public void Regress27993_TrailingSlashTrimmedFromMSBuildToolsPath() { Toolset t; t = new Toolset("x", "C:"); Assertion.AssertEquals(@"C:", t.ToolsPath); t = new Toolset("x", @"C:\"); Assertion.AssertEquals(@"C:\", t.ToolsPath); t = new Toolset("x", @"C:\\"); Assertion.AssertEquals(@"C:\", t.ToolsPath); t = new Toolset("x", @"C:\foo"); Assertion.AssertEquals(@"C:\foo", t.ToolsPath); t = new Toolset("x", @"C:\foo\"); Assertion.AssertEquals(@"C:\foo", t.ToolsPath); t = new Toolset("x", @"C:\foo\\"); Assertion.AssertEquals(@"C:\foo\", t.ToolsPath); // trim at most one slash t = new Toolset("x", @"\\foo\share"); Assertion.AssertEquals(@"\\foo\share", t.ToolsPath); t = new Toolset("x", @"\\foo\share\"); Assertion.AssertEquals(@"\\foo\share", t.ToolsPath); t = new Toolset("x", @"\\foo\share\\"); Assertion.AssertEquals(@"\\foo\share\", t.ToolsPath); // trim at most one slash }
/// <summary> /// Internal constructor /// </summary> /// <param name="engine"></param> /// <param name="toolset"></param> internal ToolsetState(Engine engine, Toolset toolset) : this(engine, toolset, new GetFiles(Directory.GetFiles), new LoadXmlFromPath(ToolsetState.LoadXmlDocumentFromPath) ) { }
public void ToolsetEscapedVersions() { string escaped = @"%25%2a%3f%40%24%28%29%3b\"; string unescaped = @"%*?@$();\"; Toolset toolsetEscaped = new Toolset(escaped, @"c:\aPath"); Toolset toolsetUnescaped = new Toolset(unescaped, @"c:\aPath"); Assertion.AssertEquals(escaped, toolsetEscaped.ToolsVersion); Assertion.AssertEquals(unescaped, toolsetUnescaped.ToolsVersion); }
/// <summary> /// Additional constructor to make unit testing the TaskRegistry support easier /// </summary> /// <remarks> /// Internal for unit test purposes only. /// </remarks> /// <param name="engine"></param> /// <param name="toolset"></param> /// <param name="getFiles"></param> /// <param name="loadXmlFromPath"></param> internal ToolsetState(Engine engine, Toolset toolset, GetFiles getFiles, LoadXmlFromPath loadXmlFromPath ) { this.parentEngine = engine; this.loggingServices = engine.LoggingServices; ErrorUtilities.VerifyThrowArgumentNull(toolset, nameof(toolset)); this.toolset = toolset; this.getFiles = getFiles; this.loadXmlFromPath = loadXmlFromPath; }
/// <summary> /// Additional constructor to make unit testing the TaskRegistry support easier /// </summary> /// <remarks> /// Internal for unit test purposes only. /// </remarks> /// <param name="engine"></param> /// <param name="toolset"></param> /// <param name="getFiles"></param> /// <param name="loadXmlFromPath"></param> internal ToolsetState(Engine engine, Toolset toolset, GetFiles getFiles, LoadXmlFromPath loadXmlFromPath ) { this.parentEngine = engine; this.loggingServices = engine.LoggingServices; ErrorUtilities.VerifyThrowArgumentNull(toolset, "toolset"); this.toolset = toolset; this.getFiles = getFiles; this.loadXmlFromPath = loadXmlFromPath; }
/// <summary> /// Reads all the toolsets and populates the given ToolsetCollection with them /// </summary> /// <param name="toolsets"></param> /// <param name="globalProperties"></param> /// <param name="initialProperties"></param> /// <param name="accumulateProperties"></param> private void ReadEachToolset(ToolsetCollection toolsets, BuildPropertyGroup globalProperties, BuildPropertyGroup initialProperties, bool accumulateProperties) { foreach (PropertyDefinition toolsVersion in ToolsVersions) { // We clone here because we don't want to interfere with the evaluation // of subsequent Toolsets; otherwise, properties found during the evaluation // of this Toolset would be persisted in initialProperties and appear // to later Toolsets as Global or Environment properties from the Engine. BuildPropertyGroup initialPropertiesClone = initialProperties.Clone(true /* deep clone */); Toolset toolset = ReadToolset(toolsVersion, globalProperties, initialPropertiesClone, accumulateProperties); if (toolset != null) { toolsets.Add(toolset); } } }
public void ToolsetImportProperties() { BuildPropertyGroup buildPropertyGroup = new BuildPropertyGroup(); buildPropertyGroup.SetProperty("n", "v"); Toolset toolset = new Toolset("toolversion", "c:\aPath", buildPropertyGroup); Assertion.AssertEquals(1, toolset.BuildProperties.Count); }
public void GetEnumerator() { Engine e = new Engine(); Toolset toolset1 = new Toolset("v1", @"c:\path"); Toolset[] toolsetArray = new Toolset[e.Toolsets.Count]; e.Toolsets.CopyTo(toolsetArray, 0); IEnumerator<Toolset> toolsetEnum = e.Toolsets.GetEnumerator(); int enumerationCounter = 0; while (toolsetEnum.MoveNext()) { Assertion.AssertEquals(true, object.ReferenceEquals(toolsetArray[enumerationCounter], toolsetEnum.Current)); Assertion.AssertEquals(toolsetArray[enumerationCounter].ToolsVersion, toolsetEnum.Current.ToolsVersion); enumerationCounter++; } }
public void ToolsetNullToolsPath() { Toolset toolset = new Toolset("toolset", null); }
public void ToolsetEmptyToolsVersion() { Toolset toolset = new Toolset(String.Empty, "c:\aPath"); }
public void ToolVersionPropertiesSetafterAddingToolset() { Engine e = new Engine(); Toolset toolset = new Toolset("toolversion", "c:\aPath"); e.Toolsets.Add(toolset); e.Toolsets["toolversion"].BuildProperties.SetProperty("n", "v"); e.Toolsets.Add(toolset); Assertion.AssertNull(e.Toolsets["toolversion"].BuildProperties["n"]); }
public void ToolPathGetRootPath() { Toolset toolset = new Toolset("toolversion", @"c:\"); Assertion.AssertEquals(@"c:\", toolset.ToolsPath); }
public void ToolVersionGet() { Toolset toolset = new Toolset("toolversion", "c:\aPath"); Assertion.AssertEquals("toolversion", toolset.ToolsVersion); }
public void ToolsetCtorErrors3() { Toolset t = new Toolset(String.Empty, "x"); }
public void ToolsetCtorErrors2() { Toolset t = new Toolset("x", null); }
public void ToolsetCtorErrors1() { Toolset t = new Toolset(null, "x"); }
public void CopyToTest_OffsetIndex() { const int OffsetIndex = 2; Engine e = new Engine(); Toolset toolset1 = new Toolset("v1", @"c:\path"); Toolset toolset2 = new Toolset("v2", @"c:\path"); e.Toolsets.Add(toolset1); Toolset[] toolsetArray = new Toolset[e.Toolsets.Count + OffsetIndex]; e.Toolsets.CopyTo(toolsetArray, OffsetIndex); Assertion.AssertEquals(e.Toolsets.Count, toolsetArray.Length - OffsetIndex); Assertion.AssertNull(toolsetArray[OffsetIndex - 1]); Assertion.AssertEquals(true, 0 < Array.IndexOf(toolsetArray, toolset1)); }
/// <summary> /// Adds a new toolset to the engine. Any pre-existing toolset with the same /// tools version is replaced with the provided toolset. /// </summary> /// <param name="toolset">the Toolset</param> internal void AddToolset(Toolset toolset) { error.VerifyThrowArgumentNull(toolset, "toolset"); if (toolsetStateMap.ContainsKey(toolset.ToolsVersion)) { // It already exists: replace it with the new toolset toolsetStateMap[toolset.ToolsVersion] = new ToolsetState(this, toolset); // We must be sure to notify all of the loaded projects with this // tools version that they are dirty so they will later pick up any changes // to the ToolsetState. DirtyProjectsUsingToolsVersion(toolset.ToolsVersion); } else { toolsetStateMap.Add(toolset.ToolsVersion, new ToolsetState(this, toolset)); } }
public void ToolsVersions() { Engine e = new Engine(); Toolset toolset1 = new Toolset("v1", @"c:\path"); IEnumerable<string> toolsVersions = e.Toolsets.ToolsVersions; Toolset[] toolsetArray = new Toolset[e.Toolsets.Count]; e.Toolsets.CopyTo(toolsetArray, 0); int counter = 0; foreach (string toolsVersion in toolsVersions) { Assertion.AssertEquals(toolsetArray[counter].ToolsVersion, toolsVersion); counter++; } Assertion.AssertEquals(toolsetArray.Length, counter); }
public void ToolsetImportPropertiesNull() { BuildPropertyGroup buildPropertyGroup = null; Toolset toolset = new Toolset("toolversion", "c:\aPath", buildPropertyGroup); Assertion.AssertEquals(0, toolset.BuildProperties.Count); }
public void ToolsetClone() { Toolset toolset = new Toolset("toolversion", "c:\aPath"); toolset.BuildProperties.SetProperty("n", "v"); Toolset toolset2 = toolset.Clone(); Assertion.AssertEquals(false, object.ReferenceEquals(toolset, toolset2)); Assertion.AssertEquals(false, object.ReferenceEquals(toolset.BuildProperties["n"], toolset2.BuildProperties["n"])); Assertion.AssertEquals(false, object.ReferenceEquals(toolset.BuildProperties, toolset2.BuildProperties)); Assertion.AssertEquals(toolset.ToolsPath, toolset2.ToolsPath); Assertion.AssertEquals(toolset.ToolsVersion, toolset2.ToolsVersion); }
public void CopyToTest_IndexZero() { Engine e = new Engine(); Toolset toolset1 = new Toolset("v1", @"c:\path"); Toolset toolset2 = new Toolset("v2", @"c:\path"); e.Toolsets.Add(toolset1); e.Toolsets.Add(toolset2); Toolset[] toolsetArray = new Toolset[e.Toolsets.Count]; e.Toolsets.CopyTo(toolsetArray, 0); Assertion.AssertEquals(e.Toolsets.Count, toolsetArray.Length); Assertion.AssertEquals(true, 0 < Array.IndexOf(toolsetArray, toolset1)); Assertion.AssertEquals(true, 0 < Array.IndexOf(toolsetArray, toolset2)); Assertion.AssertEquals(true, object.ReferenceEquals(toolsetArray[Array.IndexOf(toolsetArray, toolset2)], toolset2)); }
public void ToolPathGetTrailingSlash() { Toolset toolset = new Toolset("toolversion", @"c:\aPath\"); Assertion.AssertEquals(@"c:\aPath", toolset.ToolsPath); }
/// <summary> /// Gathers toolset data from the registry and configuration file, if any. /// NOTE: this method is internal for unit testing purposes only. /// </summary> /// <param name="toolsets"></param> /// <param name="registryReader"></param> /// <param name="configurationReader"></param> /// <param name="globalProperties"></param> /// <param name="initialProperties"></param> /// <param name="locations"></param> /// <returns></returns> internal static string ReadAllToolsets(ToolsetCollection toolsets, ToolsetRegistryReader registryReader, ToolsetConfigurationReader configurationReader, BuildPropertyGroup globalProperties, BuildPropertyGroup initialProperties, ToolsetDefinitionLocations locations) { // The 2.0 .NET Framework installer did not write a ToolsVersion key for itself in the registry. // The 3.5 installer writes one for 2.0, but 3.5 might not be installed. // The 4.0 and subsequent installers can't keep writing the 2.0 one, because (a) it causes SxS issues and (b) we // don't want it unless 2.0 is installed. // So if the 2.0 framework is actually installed, and we're reading the registry, create a toolset for it. // The registry and config file can overwrite it. if ( ((locations & ToolsetDefinitionLocations.Registry) != 0) && !toolsets.Contains("2.0") && FrameworkLocationHelper.PathToDotNetFrameworkV20 != null ) { Toolset synthetic20Toolset = new Toolset("2.0", FrameworkLocationHelper.PathToDotNetFrameworkV20, initialProperties); toolsets.Add(synthetic20Toolset); } // The ordering here is important because the configuration file should have greater precedence // than the registry string defaultToolsVersionFromRegistry = null; ToolsetRegistryReader registryReaderToUse = null; if ((locations & ToolsetDefinitionLocations.Registry) == ToolsetDefinitionLocations.Registry) { registryReaderToUse = registryReader ?? new ToolsetRegistryReader(); // We do not accumulate properties when reading them from the registry, because the order // in which values are returned to us is essentially random: so we disallow one property // in the registry to refer to another also in the registry defaultToolsVersionFromRegistry = registryReaderToUse.ReadToolsets(toolsets, globalProperties, initialProperties, false /* do not accumulate properties */); } string defaultToolsVersionFromConfiguration = null; ToolsetConfigurationReader configurationReaderToUse = null; if ((locations & ToolsetDefinitionLocations.ConfigurationFile) == ToolsetDefinitionLocations.ConfigurationFile) { if (configurationReader == null && ConfigurationFileMayHaveToolsets()) { // We haven't been passed in a fake configuration reader by a unit test, // and it looks like we have a .config file to read, so create a real // configuration reader configurationReader = new ToolsetConfigurationReader(); } if (configurationReader != null) { configurationReaderToUse = configurationReader ?? new ToolsetConfigurationReader(); // Accumulation of properties is okay in the config file because it's deterministically ordered defaultToolsVersionFromConfiguration = configurationReaderToUse.ReadToolsets(toolsets, globalProperties, initialProperties, true /* accumulate properties */); } } // We'll use the default from the configuration file if it was specified, otherwise we'll try // the one from the registry. It's possible (and valid) that neither the configuration file // nor the registry specify a default, in which case we'll just return null. string defaultToolsVersion = defaultToolsVersionFromConfiguration ?? defaultToolsVersionFromRegistry; // If we got a default version from the registry or config file, and it // actually exists, fine. // Otherwise we have to come up with one. if (defaultToolsVersion == null || !toolsets.Contains(defaultToolsVersion)) { // We're going to choose a hard coded default tools version of 2.0. defaultToolsVersion = Constants.defaultToolsVersion; // But don't overwrite any existing tools path for this default we're choosing. if (!toolsets.Contains(Constants.defaultToolsVersion)) { // There's no tools path already for 2.0, so use the path to the v2.0 .NET Framework. // If an old-fashioned caller sets BinPath property, or passed a BinPath to the constructor, // that will overwrite what we're setting here. ErrorUtilities.VerifyThrow(Constants.defaultToolsVersion == "2.0", "Getting 2.0 FX path so default should be 2.0"); string pathToFramework = FrameworkLocationHelper.PathToDotNetFrameworkV20; // We could not find the default toolsversion because it was not installed on the machine. Fallback to the // one we expect to always be there when running msbuild 4.0. if (pathToFramework == null) { pathToFramework = FrameworkLocationHelper.PathToDotNetFrameworkV40; defaultToolsVersion = Constants.defaultFallbackToolsVersion; } // Again don't overwrite any existing tools path for this default we're choosing. if (!toolsets.Contains(defaultToolsVersion)) { Toolset defaultToolset = new Toolset(defaultToolsVersion, pathToFramework, initialProperties); toolsets.Add(defaultToolset); } } } return(defaultToolsVersion); }
public void ToolVersionPropertiesSpecialProperties() { Engine e = new Engine(); Toolset toolset = new Toolset("toolversion", "c:\aPath"); toolset.BuildProperties.SetProperty("msbuildpath", "newValue"); toolset.BuildProperties.SetProperty("msbuildtoolspath", "newValue"); e.Toolsets.Add(toolset); Assertion.AssertEquals("newValue", e.Toolsets["toolversion"].BuildProperties["msbuildpath"].Value); Assertion.AssertEquals("newValue", e.Toolsets["toolversion"].BuildProperties["msbuildtoolspath"].Value); }
public void ContainsToolsVersion_escapedVersions() { Engine e = new Engine(); string escaped = @"%25%2a%3f%40%24%28%29%3b\"; string unescaped = @"%*?@$();\"; Toolset toolSetEscaped = new Toolset(escaped, @"c:\path"); Toolset toolSetUnescaped = new Toolset(unescaped, @"c:\path"); e.Toolsets.Add(toolSetEscaped); e.Toolsets.Add(toolSetUnescaped); Assertion.AssertEquals(true, e.Toolsets.Contains(escaped)); Assertion.AssertEquals(true, e.Toolsets.Contains(unescaped)); }
public void ToolsetNullToolsVersion() { Toolset toolset = new Toolset(null, "c:\aPath"); }
public void ContainsToolsVersion_notFound() { Engine e = new Engine(); Toolset toolset1 = new Toolset("v1", @"c:\path"); Toolset toolset2 = new Toolset("v2", @"c:\path"); e.Toolsets.Add(toolset1); e.Toolsets.Add(toolset2); Assertion.AssertEquals(false, e.Toolsets.Contains("notthere")); }
public void ToolsetEmptyToolsPath() { Toolset toolset = new Toolset("toolset", String.Empty); }
public void ToolsetLongPath() { string longPath = CompatibilityTestHelpers.GenerateLongPath(256); Toolset toolset = new Toolset("toolset", longPath); }
public void ToolsetInvalidPath() { string invalidPath = @"c:\invalid|path"; Toolset toolset = new Toolset("toolset", invalidPath); }
public void CopyToTest_ArrayTooSmall() { Engine e = new Engine(); Toolset toolset1 = new Toolset("v1", @"c:\path"); e.Toolsets.Add(toolset1); e.Toolsets.CopyTo(new Toolset[e.Toolsets.Count - 1], 0); }
/// <summary> /// Reads the settings for a specified tools version /// </summary> /// <param name="toolsVersion"></param> /// <param name="globalProperties"></param> /// <param name="initialProperties"></param> /// <param name="accumulateProperties"></param> /// <returns></returns> private Toolset ReadToolset(PropertyDefinition toolsVersion, BuildPropertyGroup globalProperties, BuildPropertyGroup initialProperties, bool accumulateProperties) { // Initial properties is the set of properties we're going to use to expand property expressions like $(foo) // in the values we read out of the registry or config file. We'll add to it as we pick up properties (including binpath) // from the registry or config file, so that properties there can be referenced in values below them. // After processing all the properties, we don't need initialProperties anymore. string toolsPath = null; string binPath = null; BuildPropertyGroup properties = new BuildPropertyGroup(); IEnumerable <PropertyDefinition> rawProperties = GetPropertyDefinitions(toolsVersion.Name); Expander expander = new Expander(initialProperties); foreach (PropertyDefinition property in rawProperties) { if (String.Equals(property.Name, ReservedPropertyNames.toolsPath, StringComparison.OrdinalIgnoreCase)) { toolsPath = ExpandProperty(property, expander); toolsPath = ExpandRelativePathsRelativeToExeLocation(toolsPath); if (accumulateProperties) { SetProperty ( new PropertyDefinition(ReservedPropertyNames.toolsPath, toolsPath, property.Source), initialProperties, globalProperties ); } } else if (String.Equals(property.Name, ReservedPropertyNames.binPath, StringComparison.OrdinalIgnoreCase)) { binPath = ExpandProperty(property, expander); binPath = ExpandRelativePathsRelativeToExeLocation(binPath); if (accumulateProperties) { SetProperty ( new PropertyDefinition(ReservedPropertyNames.binPath, binPath, property.Source), initialProperties, globalProperties ); } } else if (ReservedPropertyNames.IsReservedProperty(property.Name)) { // We don't allow toolsets to define reserved properties string baseMessage = ResourceUtilities.FormatResourceString("CannotModifyReservedProperty", property.Name); InvalidToolsetDefinitionException.Throw("InvalidPropertyNameInToolset", property.Name, property.Source, baseMessage); } else { // It's an arbitrary property string propertyValue = ExpandProperty(property, expander); PropertyDefinition expandedProperty = new PropertyDefinition(property.Name, propertyValue, property.Source); SetProperty(expandedProperty, properties, globalProperties); if (accumulateProperties) { SetProperty(expandedProperty, initialProperties, globalProperties); } } if (accumulateProperties) { expander = new Expander(initialProperties); } } // All tools versions must specify a value for MSBuildToolsPath (or MSBuildBinPath) if (String.IsNullOrEmpty(toolsPath) && String.IsNullOrEmpty(binPath)) { InvalidToolsetDefinitionException.Throw("MSBuildToolsPathIsNotSpecified", toolsVersion.Name, toolsVersion.Source); } // If both MSBuildBinPath and MSBuildToolsPath are present, they must be the same if (toolsPath != null && binPath != null && !toolsPath.Equals(binPath, StringComparison.OrdinalIgnoreCase)) { return(null); } Toolset toolset = null; try { toolset = new Toolset(toolsVersion.Name, toolsPath ?? binPath, properties); } catch (ArgumentException e) { InvalidToolsetDefinitionException.Throw("ErrorCreatingToolset", toolsVersion.Name, e.Message); } return(toolset); }
public void ContainsObject_notFound() { Engine e = new Engine(); Toolset toolSetToAdd = new Toolset("v1", @"c:\path"); Toolset toolSetNotAdded = new Toolset("v2", @"c:\path"); e.Toolsets.Add(toolSetToAdd); Assertion.AssertEquals(false, e.Toolsets.Contains(toolSetNotAdded)); }