コード例 #1
0
        /// <summary>
        /// Gets a <see cref="PackageSpec" /> for the specified project.
        /// </summary>
        /// <param name="project">An <see cref="IMSBuildProject" /> object that represents the project.</param>
        /// <param name="allInnerNodes">An <see cref="IReadOnlyDictionary{String,IMSBuildProject}" /> that represents all inner projects by their target framework.</param>
        /// <returns></returns>
        private PackageSpec GetPackageSpec(IMSBuildProject project, IReadOnlyDictionary <string, IMSBuildProject> allInnerNodes)
        {
            var settings = RestoreSettingsUtils.ReadSettings(
                project.GetProperty("RestoreSolutionDirectory"),
                project.GetProperty("RestoreRootConfigDirectory") ?? project.Directory,
                UriUtility.GetAbsolutePath(project.Directory, project.GetProperty("RestoreConfigFile")),
                MachineWideSettingsLazy,
                _settingsLoadContext);

            // Get the target frameworks for the project and the project instance for each framework
            var projectsByTargetFramework = GetProjectTargetFrameworks(project, allInnerNodes);

            var restoreMetadataAndTargetFrameworkInformation = GetProjectRestoreMetadataAndTargetFrameworkInformation(project, projectsByTargetFramework, settings);

            var packageSpec = new PackageSpec(restoreMetadataAndTargetFrameworkInformation.TargetFrameworkInfos)
            {
                FilePath        = project.FullPath,
                Name            = restoreMetadataAndTargetFrameworkInformation.RestoreMetadata.ProjectName,
                RestoreMetadata = restoreMetadataAndTargetFrameworkInformation.RestoreMetadata,
                RuntimeGraph    = new RuntimeGraph(
                    MSBuildStringUtility.Split($"{project.GetProperty("RuntimeIdentifiers")};{project.GetProperty("RuntimeIdentifier")}")
                    .Concat(projectsByTargetFramework.Values.SelectMany(i => MSBuildStringUtility.Split($"{i.GetProperty("RuntimeIdentifiers")};{i.GetProperty("RuntimeIdentifier")}")))
                    .Distinct(StringComparer.Ordinal)
                    .Select(rid => new RuntimeDescription(rid))
                    .ToList(),
                    MSBuildStringUtility.Split(project.GetProperty("RuntimeSupports"))
                    .Distinct(StringComparer.Ordinal)
                    .Select(s => new CompatibilityProfile(s))
                    .ToList()
                    ),
                Version = GetProjectVersion(project)
            };

            return(packageSpec);
        }
コード例 #2
0
        public void GetRestoreSettingsTask_FindConfigInProjectFolder()
        {
            // Verifies that we include any config file found in the project folder
            using (var machineWide = TestDirectory.CreateInTemp())
                using (var workingDir = TestDirectory.CreateInTemp())
                {
                    // Arrange
                    SettingsTestUtils.CreateConfigurationFile(Settings.DefaultSettingsFileName, machineWide, MachineWideSettingsConfig);
                    var machineWideSettings = new Lazy <IMachineWideSettings>(() => new TestMachineWideSettings(new Settings(machineWide, Settings.DefaultSettingsFileName, isMachineWide: true)));

                    var innerConfigFile = Path.Combine(workingDir, "sub", Settings.DefaultSettingsFileName);
                    var outerConfigFile = Path.Combine(workingDir, Settings.DefaultSettingsFileName);

                    var projectDirectory = Path.GetDirectoryName(innerConfigFile);
                    Directory.CreateDirectory(projectDirectory);

                    File.WriteAllText(innerConfigFile, InnerConfig);
                    File.WriteAllText(outerConfigFile, OuterConfig);

                    var settings = RestoreSettingsUtils.ReadSettings(null, projectDirectory, null, machineWideSettings);

                    var innerValue = SettingsUtility.GetValueForAddItem(settings, "SectionName", "inner-key");
                    var outerValue = SettingsUtility.GetValueForAddItem(settings, "SectionName", "outer-key");

                    // Assert
                    Assert.Equal("inner-value", innerValue);
                    Assert.Equal("outer-value", outerValue);
                    Assert.True(settings.GetConfigFilePaths().Contains(innerConfigFile));
                    Assert.True(settings.GetConfigFilePaths().Contains(outerConfigFile));
                }
        }
コード例 #3
0
        public void TestConfigFileProbingDirectory()
        {
            // Arrange
            var parentConfig = @"<?xml version=""1.0"" encoding=""utf-8""?>
            <configuration>
                <fallbackPackageFolders>
                    <add key=""a"" value=""C:\Temp\a"" />
                </fallbackPackageFolders>
            </configuration>";

            var unreachableConfig = @"<?xml version=""1.0"" encoding=""utf-8""?>
            <configuration>
                <fallbackPackageFolders>
                    <add key=""b"" value=""C:\Temp\b"" />
                </fallbackPackageFolders>
            </configuration>";

            var baseConfig = @"<?xml version=""1.0"" encoding=""utf-8""?>
            <configuration>
                <packageSources>
                    <add key=""c"" value=""C:\Temp\c"" />
                </packageSources>
            </configuration>";

            var configName = "NuGet.Config";

            using (var machineWide = TestDirectory.CreateInTemp())
                using (var mockParentDirectory = TestDirectory.CreateInTemp())
                {
                    // Parent
                    //       Base
                    //            Probe Path
                    //       Unreachable
                    var basePath        = Path.Combine(mockParentDirectory, "base");
                    var unreachablePath = Path.Combine(mockParentDirectory, "unreachable");
                    var probePath       = Path.Combine(basePath, "probe");
                    Directory.CreateDirectory(basePath);
                    Directory.CreateDirectory(unreachablePath);
                    Directory.CreateDirectory(probePath);

                    SettingsTestUtils.CreateConfigurationFile(configName, mockParentDirectory, parentConfig);
                    SettingsTestUtils.CreateConfigurationFile(configName, basePath, baseConfig);
                    SettingsTestUtils.CreateConfigurationFile(configName, unreachablePath, unreachableConfig);

                    SettingsTestUtils.CreateConfigurationFile(configName, machineWide, MachineWideSettingsConfig);

                    var machineWideSettings = new Lazy <IMachineWideSettings>(() => new TestMachineWideSettings(new Settings(machineWide, configName, isMachineWide: true)));

                    // Test

                    var settings  = RestoreSettingsUtils.ReadSettings(null, probePath, null, machineWideSettings);
                    var filePaths = settings.GetConfigFilePaths();

                    Assert.Equal(4, filePaths.Count()); // base, parent, app data + machine wide
                    Assert.Contains(Path.Combine(basePath, configName), filePaths);
                    Assert.Contains(Path.Combine(mockParentDirectory, configName), filePaths);
                    Assert.DoesNotContain(Path.Combine(unreachablePath, configName), filePaths);
                }
        }
コード例 #4
0
        public void TestSolutionSettings()
        {
            // Arrange
            var subFolderConfig = @"<?xml version=""1.0"" encoding=""utf-8""?>
            <configuration>
                <fallbackPackageFolders>
                    <add key=""a"" value=""C:\Temp\a"" />
                </fallbackPackageFolders>
            </configuration>";

            var baseConfig = @"<?xml version=""1.0"" encoding=""utf-8""?>
            <configuration>
                <fallbackPackageFolders>
                    <add key=""b"" value=""C:\Temp\b"" />
                </fallbackPackageFolders>
                <packageSources>
                    <add key=""c"" value=""C:\Temp\c"" />
                </packageSources>
            </configuration>";



            var baseConfigPath = "NuGet.Config";

            using (var machineWide = TestDirectory.CreateInTemp())
                using (var mockBaseDirectory = TestDirectory.CreateInTemp())
                {
                    var subFolder = Path.Combine(mockBaseDirectory, "sub");
                    var solutionDirectoryConfig = Path.Combine(mockBaseDirectory, NuGetConstants.NuGetSolutionSettingsFolder);

                    SettingsTestUtils.CreateConfigurationFile(baseConfigPath, solutionDirectoryConfig, baseConfig);
                    SettingsTestUtils.CreateConfigurationFile(baseConfigPath, subFolder, subFolderConfig);
                    SettingsTestUtils.CreateConfigurationFile(baseConfigPath, machineWide, MachineWideSettingsConfig);
                    var machineWideSettings = new Lazy <IMachineWideSettings>(() => new TestMachineWideSettings(new Settings(machineWide, baseConfigPath, isMachineWide: true)));

                    // Test

                    var settings  = RestoreSettingsUtils.ReadSettings(mockBaseDirectory, mockBaseDirectory, null, machineWideSettings);
                    var filePaths = settings.GetConfigFilePaths();

                    Assert.Equal(3, filePaths.Count()); // Solution, app data + machine wide
                    Assert.True(filePaths.Contains(Path.Combine(solutionDirectoryConfig, baseConfigPath)));
                    Assert.True(filePaths.Contains(Path.Combine(machineWide, baseConfigPath)));

                    // Test
                    settings  = RestoreSettingsUtils.ReadSettings(mockBaseDirectory, mockBaseDirectory, Path.Combine(subFolder, baseConfigPath), machineWideSettings);
                    filePaths = settings.GetConfigFilePaths();

                    Assert.Equal(1, filePaths.Count());
                    Assert.True(filePaths.Contains(Path.Combine(subFolder, baseConfigPath)));
                }
        }