public async Task DotnetToolTests_ToolRestoreWithFallback_SucceedsAsync() { using (var testDirectory = _msbuildFixture.CreateTestDirectory()) { var actualTfm = "netcoreapp2.0"; var fallbackTfm = "net46"; var projectName = "ToolRestoreProject"; var workingDirectory = Path.Combine(testDirectory, projectName); var source = Path.Combine(testDirectory, "packageSource"); var rid = "win-x64"; var packageName = string.Join("ToolPackage-", fallbackTfm, rid); var packageVersion = NuGetVersion.Parse("1.0.0"); var packages = new List <PackageIdentity>() { new PackageIdentity(packageName, packageVersion) }; var package = new SimpleTestPackageContext(packageName, packageVersion.OriginalVersion); package.Files.Clear(); package.AddFile($"tools/{fallbackTfm}/{rid}/a.dll"); package.AddFile($"tools/{fallbackTfm}/{rid}/Settings.json"); package.PackageType = PackageType.DotnetTool; package.UseDefaultRuntimeAssemblies = false; package.PackageTypes.Add(PackageType.DotnetTool); await SimpleTestPackageUtility.CreatePackagesAsync(source, package); _msbuildFixture.CreateDotnetToolProject(solutionRoot: testDirectory.Path, projectName: projectName, targetFramework: actualTfm, rid: rid, source: source, packages: packages); using (var stream = File.Open(Path.Combine(workingDirectory, projectName + ".csproj"), FileMode.Open, FileAccess.ReadWrite)) { var xml = XDocument.Load(stream); ProjectFileUtils.AddProperty( xml, "AssetTargetFallback", fallbackTfm); ProjectFileUtils.WriteXmlToFile(xml, stream); } // Act var result = _msbuildFixture.RestoreToolProject(workingDirectory, projectName, string.Empty); // Assert Assert.True(result.Item1 == 0, result.AllOutput); // Verify the assets file var lockFile = LockFileUtilities.GetLockFile(Path.Combine(testDirectory, projectName, "project.assets.json"), NullLogger.Instance); Assert.NotNull(lockFile); Assert.Equal(2, lockFile.Targets.Count); var ridTargets = lockFile.Targets.Where(e => e.RuntimeIdentifier != null ? e.RuntimeIdentifier.Equals(rid, StringComparison.CurrentCultureIgnoreCase) : false); Assert.Equal(1, ridTargets.Count()); var toolsAssemblies = ridTargets.First().Libraries.First().ToolsAssemblies; Assert.Equal(2, toolsAssemblies.Count); Assert.True(toolsAssemblies.Contains($"tools/{fallbackTfm}/{rid}/a.dll")); Assert.True(toolsAssemblies.Contains($"tools/{fallbackTfm}/{rid}/Settings.json")); } }
public void RestoreCommand_DisplaysCPVMInPreviewMessageIfCPVMEnabled() { using (var testDirectory = _msbuildFixture.CreateTestDirectory()) { // Arrange var projectName = "ClassLibrary1"; var workingDirectory = Path.Combine(testDirectory, projectName); var projectFile = Path.Combine(workingDirectory, $"{projectName}.csproj"); _msbuildFixture.CreateDotnetNewProject(testDirectory.Path, projectName, " classlib", 60000); using (var stream = new FileStream(projectFile, FileMode.Open, FileAccess.ReadWrite)) { var xml = XDocument.Load(stream); ProjectFileUtils.AddProperty( xml, "ManagePackageVersionsCentrally", "true"); ProjectFileUtils.WriteXmlToFile(xml, stream); } // The test depends on the presence of these packages and their versions. // Change to Directory.Packages.props when new cli that supports NuGet.props will be downloaded var directoryPackagesPropsName = Path.Combine(workingDirectory, $"Directory.Build.props"); var directoryPackagesPropsContent = @"<Project> <PropertyGroup> <CentralPackageVersionsFileImported>true</CentralPackageVersionsFileImported> </PropertyGroup> </Project>"; File.WriteAllText(directoryPackagesPropsName, directoryPackagesPropsContent); // Act var result = _msbuildFixture.RunDotnet(workingDirectory, "restore /v:n"); // Assert Assert.True(result.Output.Contains($"The project {projectFile} is using CentralPackageVersionManagement, a NuGet preview feature.")); } }