private TestPackageReference CreateTestPackage(string targetFrameworks, string identifier, [CallerMemberName] string callingMethod = "") { var project = new TestProject { Name = $"{targetFrameworks.Replace(';', '_')}_pkg", TargetFrameworks = targetFrameworks, }; var packageReference = new TestPackageReference( project.Name, "1.0.0", ConstantStringValues.ConstructNuGetPackageReferencePath(project, identifier, callingMethod)); if (!packageReference.NuGetPackageExists()) { var testAsset = _testAssetsManager.CreateTestProject( project, callingMethod, identifier); var packageRestoreCommand = testAsset.GetRestoreCommand(Log, relativePath: project.Name).Execute().Should().Pass(); var dependencyProjectDirectory = Path.Combine(testAsset.TestRoot, project.Name); var packagePackCommand = new PackCommand(Log, dependencyProjectDirectory).Execute().Should().Pass(); } return(packageReference); }
private TestPackageReference CreateNet461Package() { var net461Project = new TestProject { Name = $"net461_pkg", TargetFrameworks = "net461", IsSdkProject = true }; var net461PackageReference = new TestPackageReference( net461Project.Name, "1.0.0", ConstantStringValues.ConstructNuGetPackageReferencePath(net461Project)); if (!net461PackageReference.NuGetPackageExists()) { var net461PackageTestAsset = _testAssetsManager.CreateTestProject( net461Project, ConstantStringValues.TestDirectoriesNamePrefix, ConstantStringValues.NuGetSharedDirectoryNamePostfix); var packageRestoreCommand = net461PackageTestAsset.GetRestoreCommand(Log, relativePath: net461Project.Name).Execute().Should().Pass(); var dependencyProjectDirectory = Path.Combine(net461PackageTestAsset.TestRoot, net461Project.Name); var packagePackCommand = new PackCommand(Log, dependencyProjectDirectory).Execute().Should().Pass(); } return(net461PackageReference); }
private TestPackageReference CreateTestPackage(string targetFrameworks) { var project = new TestProject { Name = $"{targetFrameworks.Replace(';', '_')}_pkg", TargetFrameworks = targetFrameworks, IsSdkProject = true }; var packageReference = new TestPackageReference( project.Name, "1.0.0", ConstantStringValues.ConstructNuGetPackageReferencePath(project)); if (!packageReference.NuGetPackageExists()) { var testAsset = _testAssetsManager.CreateTestProject( project, ConstantStringValues.TestDirectoriesNamePrefix, ConstantStringValues.NuGetSharedDirectoryNamePostfix); var packageRestoreCommand = testAsset.GetRestoreCommand(Log, relativePath: project.Name).Execute().Should().Pass(); var dependencyProjectDirectory = Path.Combine(testAsset.TestRoot, project.Name); var packagePackCommand = new PackCommand(Log, dependencyProjectDirectory).Execute().Should().Pass(); } return(packageReference); }
public void Nuget_reference_compat(string referencerTarget, string testDescription, string rawDependencyTargets, bool restoreSucceeds, bool buildSucceeds) { string referencerDirectoryNamePostfix = "_" + referencerTarget + "_" + testDescription; TestProject referencerProject = GetTestProject(ConstantStringValues.ReferencerDirectoryName, referencerTarget, true); // Skip running test if not running on Windows // https://github.com/dotnet/sdk/issues/335 if (!(RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || referencerProject.BuildsOnNonWindows)) { return; } foreach (string dependencyTarget in rawDependencyTargets.Split(',', ';', ' ').ToList()) { TestProject dependencyProject = GetTestProject(ConstantStringValues.DependencyDirectoryNamePrefix + dependencyTarget.Replace('.', '_'), dependencyTarget, true); TestPackageReference dependencyPackageReference = new TestPackageReference( dependencyProject.Name, "1.0.0", ConstantStringValues.ConstructNuGetPackageReferencePath(dependencyProject)); // Skip creating the NuGet package if not running on Windows; or if the NuGet package already exists // https://github.com/dotnet/sdk/issues/335 if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || dependencyProject.BuildsOnNonWindows) { if (!dependencyPackageReference.NuGetPackageExists()) { // Create the NuGet packages var dependencyTestAsset = _testAssetsManager.CreateTestProject(dependencyProject, ConstantStringValues.TestDirectoriesNamePrefix, ConstantStringValues.NuGetSharedDirectoryNamePostfix); var dependencyRestoreCommand = dependencyTestAsset.GetRestoreCommand(Log, relativePath: dependencyProject.Name).Execute().Should().Pass(); var dependencyProjectDirectory = Path.Combine(dependencyTestAsset.TestRoot, dependencyProject.Name); var dependencyPackCommand = new PackCommand(Log, dependencyProjectDirectory); var dependencyPackResult = dependencyPackCommand.Execute().Should().Pass(); } referencerProject.PackageReferences.Add(dependencyPackageReference); } } // Skip running tests if no NuGet packages are referenced // https://github.com/dotnet/sdk/issues/335 if (referencerProject.PackageReferences == null) { return; } // Set the referencer project as an Exe unless it targets .NET Standard if (!referencerProject.ShortTargetFrameworkIdentifiers.Contains(ConstantStringValues.NetstandardToken)) { referencerProject.IsExe = true; } // Create the referencing app and run the compat test var referencerTestAsset = _testAssetsManager.CreateTestProject(referencerProject, ConstantStringValues.TestDirectoriesNamePrefix, referencerDirectoryNamePostfix); var referencerRestoreCommand = referencerTestAsset.GetRestoreCommand(Log, relativePath: referencerProject.Name); // Modify the restore command to refer to the created NuGet packages foreach (TestPackageReference packageReference in referencerProject.PackageReferences) { var source = Path.Combine(packageReference.NupkgPath, packageReference.ID, "bin", "Debug"); referencerRestoreCommand.AddSource(source); } if (restoreSucceeds) { referencerRestoreCommand.Execute().Should().Pass(); } else { referencerRestoreCommand.Execute().Should().Fail(); } var referencerBuildCommand = new BuildCommand(Log, Path.Combine(referencerTestAsset.TestRoot, referencerProject.Name)); var referencerBuildResult = referencerBuildCommand.Execute(); if (buildSucceeds) { referencerBuildResult.Should().Pass(); } else { referencerBuildResult.Should().Fail().And.HaveStdOutContaining("It cannot be referenced by a project that targets"); } }