public async Task DoesNotModifiesFileIfNoChanges() { // arrange var packageId = new PackageIdentity("Lineup", NuGetVersion.Parse("1.0.0")); var pkg = ("PackageVersionVar", "1.0.0"); var lineupPackagePath = CreateLineup(packageId, pkg); var depsFilePath = CreateProjectDepsFile(pkg); var created = File.GetLastWriteTime(depsFilePath); // act var task = new UpgradeDependencies { BuildEngine = new MockEngine(_output), DependenciesFile = depsFilePath, LineupPackageId = packageId.Id, LineupPackageRestoreSource = _tempDir, }; // assert Assert.True(await task.ExecuteAsync(), "Task is expected to pass"); var modifiedDepsFile = DependencyVersionsFile.Load(depsFilePath); Assert.Equal("1.0.0", modifiedDepsFile.VersionVariables["PackageVersionVar"]); Assert.Equal(created, File.GetLastWriteTime(depsFilePath)); }
public async Task WarnsWhenVariableIsNotInPackage() { // arrange var packageId = new PackageIdentity("Lineup", NuGetVersion.Parse("1.0.0")); var lineupPackagePath = CreateLineup(packageId); var depsFilePath = CreateProjectDepsFile(("PackageVersionVar", "1.0.0")); var engine = new MockEngine(_output); // act var task = new UpgradeDependencies { BuildEngine = engine, DependenciesFile = depsFilePath, LineupPackageId = packageId.Id, LineupPackageRestoreSource = _tempDir, }; // assert Assert.True(await task.ExecuteAsync(), "Task is expected to pass"); var warning = Assert.Single(engine.Warnings); Assert.Equal(KoreBuildErrors.Prefix + KoreBuildErrors.PackageVersionNotFoundInLineup, warning.Code); var modifiedDepsFile = DependencyVersionsFile.Load(depsFilePath); Assert.Equal("1.0.0", modifiedDepsFile.VersionVariables["PackageVersionVar"]); }
public async Task DoesNotModifyPinnedVariableValue() { // arrange var packageId = new PackageIdentity("Lineup", NuGetVersion.Parse("1.0.0")); var lineupPackagePath = CreateLineup(packageId, new VersionVariable("PackageVersionVar", "2.0.0")); var depsFilePath = CreateProjectDepsFile(new VersionVariable("PackageVersionVar", "1.0.0") { IsReadOnly = true }); // act var task = new UpgradeDependencies { BuildEngine = new MockEngine(_output), DependenciesFile = depsFilePath, LineupPackageId = packageId.Id, LineupPackageRestoreSource = _tempDir, }; // assert Assert.True(await task.ExecuteAsync(), "Task is expected to pass"); _output.WriteLine(File.ReadAllText(depsFilePath)); var modifiedDepsFile = DependencyVersionsFile.Load(depsFilePath); Assert.Equal("1.0.0", modifiedDepsFile.VersionVariables["PackageVersionVar"].Version); Assert.True(modifiedDepsFile.VersionVariables["PackageVersionVar"].IsReadOnly); }
private string CreateLineup(PackageIdentity identity, params VersionVariable[] variables) { var output = Path.Combine(_tempDir, $"{identity.Id}.{identity.Version}.nupkg"); var proj = ProjectRootElement.Create(NewProjectFileOptions.None); var depsFiles = DependencyVersionsFile.Load(proj); foreach (var item in variables) { depsFiles.Update(item.Name, item.Version); } depsFiles.Save(Path.Combine(_tempDir, "dependencies.props")); var builder = new PackageBuilder { Id = identity.Id, Version = identity.Version, Owners = { "Test" }, Authors = { "Test" }, Description = "Test lineup package" }; builder.AddFiles(_tempDir, "dependencies.props", "build/dependencies.props"); using (var stream = File.Create(output)) { builder.Save(stream); } return(output); }
private async Task <DependencyVersionsFile> TryDownloadLineupPackage(MSBuildLogger logger, string tmpNupkgPath) { VersionRange versionRange; if (string.IsNullOrEmpty(LineupPackageVersion)) { versionRange = VersionRange.AllFloating; } else if (!VersionRange.TryParse(LineupPackageVersion, out versionRange)) { Log.LogError($"{LineupPackageVersion} is not a valid NuGet package version"); return(null); } var packageVersion = await GetPackageVersion(versionRange); if (packageVersion == null) { Log.LogError($"Could not find a version of {LineupPackageId} in the version range {versionRange}."); return(null); } var packageId = new PackageIdentity(LineupPackageId, packageVersion); var request = new PackageDownloadRequest { Identity = packageId, OutputPath = tmpNupkgPath, Sources = new[] { LineupPackageRestoreSource }, }; var result = await new PackageDownloader(logger).DownloadPackagesAsync(new[] { request }, TimeSpan.FromSeconds(60), _cts.Token); if (!result) { Log.LogError("Could not download the lineup package"); return(null); } using (var nupkgReader = new PackageArchiveReader(tmpNupkgPath)) { using (var stream = nupkgReader.GetStream("build/dependencies.props")) { using (var reader = new XmlTextReader(stream)) { var projectRoot = ProjectRootElement.Create(reader); return(DependencyVersionsFile.Load(projectRoot)); } } } }
private string CreateProjectDepsFile(string depsFilePath, params VersionVariable[] variables) { var proj = ProjectRootElement.Create(NewProjectFileOptions.None); var originalDepsFile = DependencyVersionsFile.Load(proj); foreach (var item in variables) { if (item.IsReadOnly) { originalDepsFile.AddPinnedVariable(item.Name, item.Version); } else { originalDepsFile.Update(item.Name, item.Version); } } originalDepsFile.Save(depsFilePath); return(depsFilePath); }
public async Task ModifiesVariableValueUsingDepsFile() { // arrange var depsFilePath = CreateProjectDepsFile(("PackageVersionVar", "1.0.0")); var updatedDepsFilePath = CreateProjectDepsFile(Path.Combine(_tempDir, "dependencies.props"), ("PackageVersionVar", "2.0.0")); // act var task = new UpgradeDependencies { BuildEngine = new MockEngine(_output), DependenciesFile = depsFilePath, LineupDependenciesFile = updatedDepsFilePath }; // assert Assert.True(await task.ExecuteAsync(), "Task is expected to pass"); var modifiedDepsFile = DependencyVersionsFile.Load(depsFilePath); Assert.Equal("2.0.0", modifiedDepsFile.VersionVariables["PackageVersionVar"]); }
public async Task SnapsInternalAspNetCoreSdkToBuildTools() { // arrange var packageId = new PackageIdentity("Lineup", NuGetVersion.Parse("1.0.0")); var lineupPackagePath = CreateLineup(packageId, ("InternalAspNetCoreSdkPackageVersion", "2.0.0")); var depsFilePath = CreateProjectDepsFile(("InternalAspNetCoreSdkPackageVersion", "1.0.0")); // act var task = new UpgradeDependencies { BuildEngine = new MockEngine(_output), DependenciesFile = depsFilePath, LineupPackageId = packageId.Id, LineupPackageRestoreSource = _tempDir, }; // assert Assert.True(await task.ExecuteAsync(), "Task is expected to pass"); var modifiedDepsFile = DependencyVersionsFile.Load(depsFilePath); Assert.Equal(KoreBuildVersion.Current, modifiedDepsFile.VersionVariables["InternalAspNetCoreSdkPackageVersion"]); }