コード例 #1
0
        public void CombinePathsTest()
        {
            // These tests run in .NET 4+, so we can cheat
            var root = @"c:\";

            Assert.Equal(
                Path.Combine(root, "path1"),
                FileUtilities.CombinePaths(root, "path1"));

            Assert.Equal(
                Path.Combine(root, "path1", "path2", "file.txt"),
                FileUtilities.CombinePaths(root, "path1", "path2", "file.txt"));
        }
コード例 #2
0
        /// <summary>
        /// Gathers toolset data from the registry + configuration file + VS setup API, if any.
        /// NOTE:  this method is internal for unit testing purposes only.
        /// </summary>
        internal static string ReadAllToolsets
        (
            Dictionary <string, Toolset> toolsets,
#if FEATURE_WIN32_REGISTRY
            ToolsetRegistryReader registryReader,
#endif
#if FEATURE_SYSTEM_CONFIGURATION
            ToolsetConfigurationReader configurationReader,
#endif
            PropertyDictionary <ProjectPropertyInstance> environmentProperties,
            PropertyDictionary <ProjectPropertyInstance> globalProperties,
            ToolsetDefinitionLocations locations
        )
        {
            var defaultVer = ReadAllToolsetsNative
                             (
                toolsets,

#if FEATURE_WIN32_REGISTRY
                registryReader,
#endif
#if FEATURE_SYSTEM_CONFIGURATION
                configurationReader,
#endif
                environmentProperties,
                globalProperties,
                locations
                             );

            const string _CUR       = MSBuildConstants.CurrentToolsVersion;
            string       currentDir = BuildEnvironmentHelper.Instance.CurrentMSBuildToolsDirectory.TrimEnd(Path.DirectorySeparatorChar);

            foreach (var vs in VisualStudioLocationHelper.GetInstances())
            {
                string vstr    = $"{vs.Version.Major}.0";
                string toolbin = FileUtilities.CombinePaths
                                 (
                    vs.Path,
                    "MSBuild",
                    vs.Version.Major >= 16 ? _CUR : vstr,
                    "Bin"
                                 );

                if (IntPtr.Size == 8)
                {
                    string toolbin64 = FileUtilities.CombinePaths(toolbin, "amd64");
                    if (Directory.Exists(toolbin64))
                    {
                        toolbin = toolbin64;
                    }
                }

                if (!toolsets.ContainsKey(vstr))
                {
                    // For Mono
                    var buildProperties = CreateStandardProperties(globalProperties, vstr, NativeMethodsShared.FrameworkBasePath, toolbin);

                    toolsets.Add
                    (
                        vstr,
                        new Toolset
                        (
                            vstr,
                            toolbin,
                            buildProperties,
                            environmentProperties,
                            globalProperties,
                            null,
                            currentDir,
                            string.Empty
                        )
                    );
                }
            }

            if (!toolsets.ContainsKey(_CUR))
            {
                var actual = toolsets.GetMostActual();
                if (actual != null)
                {
                    toolsets.Add(_CUR, actual);
                }
                else
                {
                    toolsets.Add
                    (
                        _CUR,
                        new Toolset
                        (
                            _CUR,
                            currentDir,
                            new PropertyDictionary <ProjectPropertyInstance>(),
                            new PropertyDictionary <ProjectPropertyInstance>(),
                            currentDir,
                            string.Empty
                        )
                    );
                }
            }

            return(defaultVer);
        }