public void MSBuildToolsetsTest_Basic() { ToolsetConfigurationReaderTestHelper.WriteConfigFile(ObjectModelHelpers.CleanupFileContents(@" <configuration> <configSections> <section name=""msbuildToolsets"" type=""Microsoft.Build.Evaluation.ToolsetConfigurationSection, Microsoft.Build"" /> </configSections> <msbuildToolsets default=""2.0""> <toolset toolsVersion=""2.0""> <property name=""MSBuildBinPath"" value=""D:\windows\Microsoft.NET\Framework\v2.0.x86ret\""/> </toolset> </msbuildToolsets> </configuration>")); Configuration config = ToolsetConfigurationReaderTestHelper.ReadApplicationConfigurationTest(); ConfigurationSection section = config.GetSection(s_msbuildToolsets); ToolsetConfigurationSection msbuildToolsetSection = section as ToolsetConfigurationSection; Assert.Equal(msbuildToolsetSection.MSBuildOverrideTasksPath, null); Assert.Equal(msbuildToolsetSection.Default, "2.0"); Assert.Equal(1, msbuildToolsetSection.Toolsets.Count); Assert.Equal(msbuildToolsetSection.Toolsets.GetElement(0).toolsVersion, "2.0"); Assert.Equal(msbuildToolsetSection.Toolsets.GetElement("2.0").PropertyElements.Count, 1); Assert.Equal(msbuildToolsetSection.Toolsets.GetElement("2.0").PropertyElements.GetElement("MSBuildBinPath").Value, @"D:\windows\Microsoft.NET\Framework\v2.0.x86ret\"); }
public void ToolsVersionTest_SingleElement() { ToolsetConfigurationReaderTestHelper.WriteConfigFile(ObjectModelHelpers.CleanupFileContents(@" <configuration> <configSections> <section name=""msbuildToolsets"" type=""Microsoft.Build.Evaluation.ToolsetConfigurationSection, Microsoft.Build"" /> </configSections> <msbuildToolsets default=""4.0""> <toolset toolsVersion=""4.0""> <property name=""MSBuildBinPath"" value=""D:\windows\Microsoft.NET\Framework\v3.5.x86ret\""/> </toolset> </msbuildToolsets> </configuration>")); Configuration config = ToolsetConfigurationReaderTestHelper.ReadApplicationConfigurationTest(); ToolsetConfigurationSection msbuildToolsetSection = config.GetSection(s_msbuildToolsets) as ToolsetConfigurationSection; Assert.Equal("4.0", msbuildToolsetSection.Default); Assert.Single(msbuildToolsetSection.Toolsets); Assert.Equal("4.0", msbuildToolsetSection.Toolsets.GetElement(0).toolsVersion); Assert.Single(msbuildToolsetSection.Toolsets.GetElement("4.0").PropertyElements); Assert.Equal( @"D:\windows\Microsoft.NET\Framework\v3.5.x86ret\", msbuildToolsetSection.Toolsets.GetElement("4.0").PropertyElements.GetElement("MSBuildBinPath").Value); }
public void PropertyTest_GetValueByName() { ToolsetConfigurationReaderTestHelper.WriteConfigFile(ObjectModelHelpers.CleanupFileContents(@" <configuration> <configSections> <section name=""msbuildToolsets"" type=""Microsoft.Build.Evaluation.ToolsetConfigurationSection, Microsoft.Build"" /> </configSections> <msbuildToolsets default=""2.0""> <toolset toolsVersion=""2.0""> <property name=""MSBuildBinPath"" value=""D:\windows\Microsoft.NET\Framework\v2.0.x86ret\""/> <property name=""SomeOtherPropertyName"" value=""SomeOtherPropertyValue""/> </toolset> </msbuildToolsets> </configuration>")); Configuration config = ToolsetConfigurationReaderTestHelper.ReadApplicationConfigurationTest(); ToolsetConfigurationSection msbuildToolsetSection = config.GetSection(s_msbuildToolsets) as ToolsetConfigurationSection; // Verifications Assert.Equal(msbuildToolsetSection.Default, "2.0"); Assert.Equal(1, msbuildToolsetSection.Toolsets.Count); Assert.Equal(2, msbuildToolsetSection.Toolsets.GetElement("2.0").PropertyElements.Count); Assert.Equal(@"D:\windows\Microsoft.NET\Framework\v2.0.x86ret\", msbuildToolsetSection.Toolsets.GetElement("2.0").PropertyElements.GetElement("MSBuildBinPath").Value); Assert.Equal(@"SomeOtherPropertyValue", msbuildToolsetSection.Toolsets.GetElement("2.0").PropertyElements.GetElement("SomeOtherPropertyName").Value); }
public void ToolsVersionTest_MultipleElementsWithSameName() { Assert.Throws <ConfigurationErrorsException>(() => { ToolsetConfigurationReaderTestHelper.WriteConfigFile(ObjectModelHelpers.CleanupFileContents(@" <configuration> <configSections> <section name=""msbuildToolsets"" type=""Microsoft.Build.Evaluation.ToolsetConfigurationSection, Microsoft.Build"" /> </configSections> <msbuildToolsets default=""2.0""> <toolset toolsVersion=""2.0""> <property name=""MSBuildBinPath"" value=""D:\windows\Microsoft.NET\Framework\v2.0.x86ret\""/> </toolset> <toolset toolsVersion=""2.0""> <property name=""MSBuildBinPath"" value=""D:\windows\Microsoft.NET\Framework\v3.5.x86ret\""/> </toolset> </msbuildToolsets> </configuration>")); Configuration config = ToolsetConfigurationReaderTestHelper.ReadApplicationConfigurationTest(); ToolsetConfigurationSection msbuildToolsetSection = config.GetSection(s_msbuildToolsets) as ToolsetConfigurationSection; } ); }
internal static ToolsetConfigurationSection ReadToolsetConfigurationSection(Configuration configuration) { ToolsetConfigurationSection configurationSection = null; // This will be null if the application config file does not have the following section // definition for the msbuildToolsets section as the first child element. // <configSections> // <section name=""msbuildToolsets"" type=""Microsoft.Build.Evaluation.ToolsetConfigurationSection, Microsoft.Build"" /> // </configSections>"; // Note that the application config file may or may not contain an msbuildToolsets element. // For example: // If section definition is present and section is not present, this value is not null // If section definition is not present and section is also not present, this value is null // If the section definition is not present and section is present, then this value is null if (null != configuration) { ConfigurationSection msbuildSection = configuration.GetSection("msbuildToolsets"); configurationSection = msbuildSection as ToolsetConfigurationSection; if (configurationSection == null && msbuildSection != null) // we found msbuildToolsets but the wrong type of handler { if (String.IsNullOrEmpty(msbuildSection.SectionInformation.Type) || msbuildSection.SectionInformation.Type.IndexOf("Microsoft.Build", StringComparison.OrdinalIgnoreCase) >= 0) { // Set the configuration type handler to the current ToolsetConfigurationSection type msbuildSection.SectionInformation.Type = typeof(ToolsetConfigurationSection).AssemblyQualifiedName; try { // fabricate a temporary config file with the correct section handler type in it string tempFileName = FileUtilities.GetTemporaryFile(); // Save the modified config configuration.SaveAs(tempFileName + ".config"); // Open the configuration again, the new type for the section handler will do its stuff // Note that the OpenExeConfiguration call uses the config filename *without* the .config // extension configuration = ConfigurationManager.OpenExeConfiguration(tempFileName); // Get the toolset information from the section using our real handler configurationSection = configuration.GetSection("msbuildToolsets") as ToolsetConfigurationSection; File.Delete(tempFileName + ".config"); File.Delete(tempFileName); } catch (Exception ex) { if (ExceptionHandling.NotExpectedException(ex)) { throw; } } } } } return(configurationSection); }
public void PropertyTest_ValueNotSpecified() { ToolsetConfigurationReaderTestHelper.WriteConfigFile(ObjectModelHelpers.CleanupFileContents(@" <configuration> <configSections> <section name=""msbuildToolsets"" type=""Microsoft.Build.Evaluation.ToolsetConfigurationSection, Microsoft.Build"" /> </configSections> <msbuildToolsets default=""4.0""> <toolset name=""4.0""> <property name=""MSBuildBinPath"" /> </toolset> </msbuildToolsets> </configuration>")); Configuration config = ToolsetConfigurationReaderTestHelper.ReadApplicationConfigurationTest(); ToolsetConfigurationSection msbuildToolsetSection = config.GetSection(s_msbuildToolsets) as ToolsetConfigurationSection; }
public void PropertyTest_NameNotSpecified() { ToolsetConfigurationReaderTestHelper.WriteConfigFile(ObjectModelHelpers.CleanupFileContents(@" <configuration> <configSections> <section name=""msbuildToolsets"" type=""Microsoft.Build.Evaluation.ToolsetConfigurationSection, Microsoft.Build"" /> </configSections> <msbuildToolsets default=""4.0""> <toolset toolsVersion=""4.0""> <property value=""D:\windows\Microsoft.NET\Framework\v3.5.x86ret\""/> </toolset> </msbuildToolsets> </configuration>")); Configuration config = ToolsetConfigurationReaderTestHelper.ReadApplicationConfigurationTest(); ToolsetConfigurationSection msbuildToolsetSection = config.GetSection(s_msbuildToolsets) as ToolsetConfigurationSection; }
public void MSBuildToolsetsTest_EmptyElement() { ToolsetConfigurationReaderTestHelper.WriteConfigFile(ObjectModelHelpers.CleanupFileContents(@" <configuration> <configSections> <section name=""msbuildToolsets"" type=""Microsoft.Build.Evaluation.ToolsetConfigurationSection, Microsoft.Build"" /> </configSections> <msbuildToolsets /> </configuration>")); Configuration config = ToolsetConfigurationReaderTestHelper.ReadApplicationConfigurationTest(); ToolsetConfigurationSection msbuildToolsetSection = config.GetSection(s_msbuildToolsets) as ToolsetConfigurationSection; Assert.Equal(msbuildToolsetSection.MSBuildOverrideTasksPath, null); Assert.NotNull(msbuildToolsetSection); Assert.Equal(null, msbuildToolsetSection.Default); Assert.NotNull(msbuildToolsetSection.Toolsets); Assert.Equal(0, msbuildToolsetSection.Toolsets.Count); }
public void MSBuildToolsetsTest_BasicWithOtherConfigEntries() { // NOTE: for some reason, <configSections> MUST be the first element under <configuration> // for the API to read it. The docs don't make this clear. ToolsetConfigurationReaderTestHelper.WriteConfigFile(ObjectModelHelpers.CleanupFileContents(@" <configuration> <configSections> <section name=""msbuildToolsets"" type=""Microsoft.Build.Evaluation.ToolsetConfigurationSection, Microsoft.Build"" /> </configSections> <startup> <supportedRuntime imageVersion=""v2.0.60510"" version=""v2.0.x86chk""/> <requiredRuntime imageVersion=""v2.0.60510"" version=""v2.0.x86chk"" safemode=""true""/> </startup> <msbuildToolsets default=""2.0""> <toolset toolsVersion=""2.0""> <property name=""MSBuildBinPath"" value=""D:\windows\Microsoft.NET\Framework\v2.0.x86ret\""/> </toolset> </msbuildToolsets> <runtime> <assemblyBinding xmlns=""urn:schemas-microsoft-com:asm.v1""> <dependentAssembly> <assemblyIdentity name=""Microsoft.Build.Framework"" publicKeyToken=""b03f5f7f11d50a3a"" culture=""neutral""/> <bindingRedirect oldVersion=""0.0.0.0-99.9.9.9"" newVersion=""2.0.0.0""/> </dependentAssembly> </assemblyBinding> </runtime> </configuration>")); Configuration config = ToolsetConfigurationReaderTestHelper.ReadApplicationConfigurationTest(); ToolsetConfigurationSection msbuildToolsetSection = config.GetSection(s_msbuildToolsets) as ToolsetConfigurationSection; Assert.Equal("2.0", msbuildToolsetSection.Default); Assert.Single(msbuildToolsetSection.Toolsets); Assert.Equal("2.0", msbuildToolsetSection.Toolsets.GetElement(0).toolsVersion); Assert.Single(msbuildToolsetSection.Toolsets.GetElement("2.0").PropertyElements); Assert.Equal( @"D:\windows\Microsoft.NET\Framework\v2.0.x86ret\", msbuildToolsetSection.Toolsets.GetElement("2.0").PropertyElements.GetElement("MSBuildBinPath").Value); Assert.Empty(msbuildToolsetSection.Toolsets.GetElement(0).AllProjectImportSearchPaths); }
public void ExtensionPathsTest_Basic1() { // NOTE: for some reason, <configSections> MUST be the first element under <configuration> // for the API to read it. The docs don't make this clear. ToolsetConfigurationReaderTestHelper.WriteConfigFile(ObjectModelHelpers.CleanupFileContents(@" <configuration> <configSections> <section name=""msbuildToolsets"" type=""Microsoft.Build.Evaluation.ToolsetConfigurationSection, Microsoft.Build"" /> </configSections> <msbuildToolsets default=""2.0""> <toolset toolsVersion=""2.0""> <property name=""MSBuildBinPath"" value=""D:\windows\Microsoft.NET\Framework\v2.0.x86ret\""/> <property name=""MSBuildToolsPath"" value=""D:\windows\Microsoft.NET\Framework\v2.0.x86ret\""/> <projectImportSearchPaths> <searchPaths os=""windows""> <property name=""MSBuildExtensionsPath"" value=""c:\foo""/> <property name=""MSBuildExtensionsPath64"" value=""c:\foo64;c:\bar64""/> </searchPaths> <searchPaths os=""osx""> <property name=""MSBuildExtensionsPath"" value=""/tmp/foo""/> <property name=""MSBuildExtensionsPath32"" value=""/tmp/foo32;/tmp/bar32""/> </searchPaths> <searchPaths os=""unix""> <property name=""MSBuildExtensionsPath"" value=""/tmp/bar""/> </searchPaths> </projectImportSearchPaths> </toolset> </msbuildToolsets> </configuration>")); Configuration config = ToolsetConfigurationReaderTestHelper.ReadApplicationConfigurationTest(); ToolsetConfigurationSection msbuildToolsetSection = config.GetSection(s_msbuildToolsets) as ToolsetConfigurationSection; Assert.Equal(msbuildToolsetSection.Default, "2.0"); Assert.Equal(1, msbuildToolsetSection.Toolsets.Count); Assert.Equal(msbuildToolsetSection.Toolsets.GetElement(0).toolsVersion, "2.0"); Assert.Equal(msbuildToolsetSection.Toolsets.GetElement("2.0").PropertyElements.Count, 2); Assert.Equal(msbuildToolsetSection.Toolsets.GetElement("2.0").PropertyElements.GetElement("MSBuildBinPath").Value, @"D:\windows\Microsoft.NET\Framework\v2.0.x86ret\"); Assert.Equal(msbuildToolsetSection.Toolsets.GetElement(0).AllProjectImportSearchPaths.Count, 3); var allPaths = msbuildToolsetSection.Toolsets.GetElement(0).AllProjectImportSearchPaths; Assert.Equal(allPaths.GetElement(0).OS, "windows"); Assert.Equal(allPaths.GetElement(0).PropertyElements.Count, 2); Assert.Equal(allPaths.GetElement(0).PropertyElements.GetElement("MSBuildExtensionsPath").Value, @"c:\foo"); Assert.Equal(allPaths.GetElement(0).PropertyElements.GetElement("MSBuildExtensionsPath64").Value, @"c:\foo64;c:\bar64"); Assert.Equal(allPaths.GetElement(1).OS, "osx"); Assert.Equal(allPaths.GetElement(1).PropertyElements.Count, 2); Assert.Equal(allPaths.GetElement(1).PropertyElements.GetElement("MSBuildExtensionsPath").Value, @"/tmp/foo"); Assert.Equal(allPaths.GetElement(1).PropertyElements.GetElement("MSBuildExtensionsPath32").Value, @"/tmp/foo32;/tmp/bar32"); Assert.Equal(allPaths.GetElement(2).OS, "unix"); Assert.Equal(allPaths.GetElement(2).PropertyElements.Count, 1); Assert.Equal(allPaths.GetElement(2).PropertyElements.GetElement("MSBuildExtensionsPath").Value, @"/tmp/bar"); var reader = GetStandardConfigurationReader(); Dictionary <string, Toolset> toolsets = new Dictionary <string, Toolset>(StringComparer.OrdinalIgnoreCase); string msbuildOverrideTasksPath = null; string defaultOverrideToolsVersion = null; reader.ReadToolsets(toolsets, new PropertyDictionary <ProjectPropertyInstance>(), new PropertyDictionary <ProjectPropertyInstance>(), true, out msbuildOverrideTasksPath, out defaultOverrideToolsVersion); Dictionary <string, ProjectImportPathMatch> pathsTable = toolsets["2.0"].ImportPropertySearchPathsTable; if (NativeMethodsShared.IsWindows) { CheckPathsTable(pathsTable, "MSBuildExtensionsPath", new string[] { "c:\\foo" }); CheckPathsTable(pathsTable, "MSBuildExtensionsPath64", new string[] { "c:\\foo64", "c:\\bar64" }); } else if (NativeMethodsShared.IsOSX) { CheckPathsTable(pathsTable, "MSBuildExtensionsPath", new string[] { "/tmp/foo" }); CheckPathsTable(pathsTable, "MSBuildExtensionsPath32", new string[] { "/tmp/foo32", "/tmp/bar32" }); } else { CheckPathsTable(pathsTable, "MSBuildExtensionsPath", new string[] { "/tmp/bar" }); } }