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); }
public void HasServiceableFlagWhenArgumentPassed() { var root = Temp.CreateDirectory(); var testLibDir = root.CreateDirectory("TestLibrary"); var sourceTestLibDir = Path.Combine(_testProjectsRoot, "TestLibraryWithConfiguration"); CopyProjectToTempDir(sourceTestLibDir, testLibDir); var testProject = GetProjectPath(testLibDir); var packCommand = new PackCommand(testProject, configuration: "Debug", serviceable: true); var result = packCommand.Execute(); result.Should().Pass(); var outputDir = new DirectoryInfo(Path.Combine(testLibDir.Path, "bin", "Debug")); outputDir.Should().Exist(); outputDir.Should().HaveFiles(new[] { "TestLibrary.1.0.0.nupkg", "TestLibrary.1.0.0.symbols.nupkg" }); var outputPackage = Path.Combine(outputDir.FullName, "TestLibrary.1.0.0.nupkg"); var zip = ZipFile.Open(outputPackage, ZipArchiveMode.Read); zip.Entries.Should().Contain(e => e.FullName == "TestLibrary.nuspec"); var manifestReader = new StreamReader(zip.Entries.First(e => e.FullName == "TestLibrary.nuspec").Open()); var nuspecXml = XDocument.Parse(manifestReader.ReadToEnd()); var node = nuspecXml.Descendants().Single(e => e.Name.LocalName == "serviceable"); Assert.Equal("true", node.Value); }
public void Clean_should_remove_bin_output(bool multiTarget, string targetFramework) { TestAsset helloWorldAsset = CreateTestAsset( multiTarget, nameof(Clean_should_remove_bin_output) + multiTarget + targetFramework, targetFramework: targetFramework); _testRoot = helloWorldAsset.TestRoot; var packCommand = new PackCommand(Log, helloWorldAsset.TestRoot); packCommand.Execute().Should().Pass(); var cleanCommand = new CleanCommand(Log, helloWorldAsset.TestRoot); cleanCommand.Execute().Should().Pass(); var outputDirectory = packCommand.GetOutputDirectory("netcoreapp2.1"); string windowShimPath = Path.Combine(outputDirectory.FullName, $"shims/netcoreapp2.1/win-x64/{_customToolCommandName}.exe"); File.Exists(windowShimPath).Should().BeFalse($"Shim {windowShimPath} should not exists"); string osxShimPath = Path.Combine(outputDirectory.FullName, $"shims/netcoreapp2.1/osx.10.12-x64/{_customToolCommandName}"); File.Exists(osxShimPath).Should().BeFalse($"Shim {osxShimPath} should not exists"); }
public void It_produces_valid_shims_when_the_first_build_is_wrong(bool multiTarget, string targetFramework) { // The first build use wrong package id and should embed wrong string to shims. However, the pack should produce correct shim // since it includes build target. And the incremental build should consider the shim to be invalid and recreate that. if (!Environment.Is64BitOperatingSystem) { // only sample test on win-x64 since shims are RID specific return; } TestAsset helloWorldAsset = CreateTestAsset(multiTarget, "It_produces_valid_shims2" + multiTarget + targetFramework, targetFramework: targetFramework); var testRoot = helloWorldAsset.TestRoot; var buildCommand = new BuildCommand(helloWorldAsset); buildCommand.Execute("/p:PackageId=wrongpackagefirstbuild"); var packCommand = new PackCommand(Log, helloWorldAsset.TestRoot); packCommand.Execute().Should().Pass(); var nugetPackage = packCommand.GetNuGetPackage(); _packageId = Path.GetFileNameWithoutExtension(packCommand.ProjectFile); AssertValidShim(testRoot, nugetPackage); }
public void It_packs_successfully() { var helloWorldAsset = _testAssetsManager .CopyTestAsset("HelloWorld", "PackHelloWorld") .WithSource(); var packCommand = new PackCommand(Log, helloWorldAsset.TestRoot); packCommand .Execute() .Should() .Pass(); // Validate the contents of the NuGet package by looking at the generated .nuspec file, as that's simpler // than unzipping and inspecting the .nupkg string nuspecPath = packCommand.GetIntermediateNuspecPath(); var nuspec = XDocument.Load(nuspecPath); var ns = nuspec.Root.Name.Namespace; XElement filesSection = nuspec.Root.Element(ns + "files"); var fileTargets = filesSection.Elements().Select(files => files.Attribute("target").Value).ToList(); var expectedFileTargets = new[] { @"lib\netcoreapp2.1\HelloWorld.runtimeconfig.json", @"lib\netcoreapp2.1\HelloWorld.dll" }.Select(p => p.Replace('\\', Path.DirectorySeparatorChar)); fileTargets.Should().BeEquivalentTo(expectedFileTargets); }
private string SetupNuGetPackage(bool multiTarget, [CallerMemberName] string callingMethod = "") { TestAsset helloWorldAsset = _testAssetsManager .CopyTestAsset("PortableTool", callingMethod + multiTarget) .WithSource() .WithProjectChanges(project => { XNamespace ns = project.Root.Name.Namespace; XElement propertyGroup = project.Root.Elements(ns + "PropertyGroup").First(); if (multiTarget) { propertyGroup.Element(ns + "TargetFramework").Remove(); propertyGroup.Add(new XElement(ns + "TargetFrameworks", "netcoreapp2.1")); } }) .Restore(Log); _testRoot = helloWorldAsset.TestRoot; var packCommand = new PackCommand(Log, helloWorldAsset.TestRoot); packCommand.Execute(); return(packCommand.GetNuGetPackage()); }
public void ItPacksContentForLibraries() { var projectDirectory = TestAssets .GetProjectJson("PJTestLibraryWithConfiguration") .CreateInstance() .WithSourceFiles() .WithRestoreFiles() .WithEmptyGlobalJson() .Root; new TestCommand("dotnet") .WithForwardingToConsole() .Execute($"migrate {projectDirectory.FullName}") .Should() .Pass(); var command = new RestoreCommand() .WithWorkingDirectory(projectDirectory) .Execute() .Should() .Pass(); var result = new PackCommand() .WithWorkingDirectory(projectDirectory) .ExecuteWithCapturedOutput() .Should() .Pass(); using (var archive = ZipFile.OpenRead( Path.Combine(projectDirectory.FullName, "bin", "debug", "PJTestLibraryWithConfiguration.1.0.0.nupkg"))) { archive.Entries.Select(e => e.FullName).Should().Contain("dir/contentitem.txt"); } }
public void HasServiceableFlagWhenArgumentPassed() { var testInstance = TestAssets.Get("TestLibraryWithConfiguration") .CreateInstance() .WithSourceFiles() .WithRestoreFiles() .WithBuildFiles(); var packCommand = new PackCommand(configuration: "Debug", serviceable: true) .WithWorkingDirectory(testInstance.Root); var result = packCommand.Execute(); result.Should().Pass(); // netstandard1.5 is a workaround for https://github.com/dotnet/sdk/issues/318 var outputDir = testInstance.Root.GetDirectory("bin", "Debug", "netstandard1.5"); outputDir.Should().Exist() .And.HaveFile("TestLibraryWithConfiguration.1.0.0.nupkg"); var outputPackage = outputDir.GetFile("TestLibraryWithConfiguration.1.0.0.nupkg"); var zip = ZipFile.Open(outputPackage.FullName, ZipArchiveMode.Read); zip.Entries.Should().Contain(e => e.FullName == "TestLibraryWithConfiguration.nuspec"); var manifestReader = new StreamReader(zip.Entries.First(e => e.FullName == "TestLibraryWithConfiguration.nuspec").Open()); var nuspecXml = XDocument.Parse(manifestReader.ReadToEnd()); var node = nuspecXml.Descendants().Single(e => e.Name.LocalName == "serviceable"); Assert.Equal("true", node.Value); }
public void It_finds_commandName_and_put_in_setting_file() { const string explicitCommandName = "explicit_command_name"; TestAsset helloWorldAsset = _testAssetsManager .CopyTestAsset("PortableTool", "PackPortableToolToolCommandName") .WithSource() .WithProjectChanges(project => { XNamespace ns = project.Root.Name.Namespace; XElement propertyGroup = project.Root.Elements(ns + "PropertyGroup").First(); propertyGroup.Add(new XElement("ToolCommandName", explicitCommandName)); }) .Restore(Log); var packCommand = new PackCommand(Log, helloWorldAsset.TestRoot); packCommand.Execute(); var nugetPackage = packCommand.GetNuGetPackage(); using (var nupkgReader = new PackageArchiveReader(nugetPackage)) { var anyTfm = nupkgReader.GetSupportedFrameworks().First().GetShortFolderName(); var tmpfilePath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); string copiedFile = nupkgReader.ExtractFile($"tools/{anyTfm}/any/DotnetToolSettings.xml", tmpfilePath, null); XDocument.Load(copiedFile) .Element("DotNetCliTool") .Element("Commands") .Element("Command") .Attribute("Name") .Value .Should().Be(explicitCommandName); } }
private string SetupNuGetPackage(bool multiTarget, [CallerMemberName] string callingMethod = "") { TestAsset helloWorldAsset = _testAssetsManager .CopyTestAsset("PortableTool", callingMethod + multiTarget) .WithSource() .WithProjectChanges(project => { XNamespace ns = project.Root.Name.Namespace; XElement propertyGroup = project.Root.Elements(ns + "PropertyGroup").First(); propertyGroup.Add(new XElement(ns + "PackAsToolShimRuntimeIdentifiers", "win-x64;osx.10.12-x64")); propertyGroup.Add(new XElement(ns + "ToolCommandName", _customToolCommandName)); if (multiTarget) { propertyGroup.Element(ns + "TargetFramework").Remove(); propertyGroup.Add(new XElement(ns + "TargetFrameworks", "netcoreapp2.1")); } }) .Restore(Log); _testRoot = helloWorldAsset.TestRoot; var packCommand = new PackCommand(Log, helloWorldAsset.TestRoot); packCommand.Execute(); _packageId = Path.GetFileNameWithoutExtension(packCommand.ProjectFile); return(packCommand.GetNuGetPackage()); }
private static async Task InternalMain(string[] args, PackageHelper packageHelper) { // now uses 'verbs' so each verb is a command // // e.g umbpack init or umbpack push // // these are handled by the Command classes. var parser = new Parser(with => { with.HelpWriter = null; // with.HelpWriter = Console.Out; with.AutoVersion = false; with.CaseSensitive = false; }); // TODO: could load the verbs by interface or class var parserResults = parser.ParseArguments <PackOptions, PushOptions, InitOptions>(args); parserResults .WithParsed <PackOptions>(opts => PackCommand.RunAndReturn(opts).Wait()) .WithParsed <PushOptions>(opts => PushCommand.RunAndReturn(opts, packageHelper).Wait()) .WithParsed <InitOptions>(opts => InitCommand.RunAndReturn(opts)) .WithNotParsed(async errs => await DisplayHelp(parserResults, errs)); }
public static Response Pack(NuGetPackRequest request) { var console = new Console(); var command = new PackCommand { BasePath = PathTools.OptimizePath(request.BaseDirectory), OutputDirectory = PathTools.OptimizePath(request.OutputDirectory), Version = request.Version, Console = console, CurrentDirectory = request.BaseDirectory, Verbosity = Verbosity.Detailed, }; command.Arguments.Add(request.SpecPath); try { command.Execute(); } catch (Exception e) { console.WriteError(e.ToString()); } return(new Response(console.Messages)); }
public override IResult Execute() { #region Code for sending command to remote system PacketElements CommandPacketElems = new PacketElements(); CommandPacketElems.ActualCommand = Command; long HeaderValue = long.Parse(ConfigurationSettings.AppSettings["CommandHeader"]); CommandPacketElems.Header = HeaderValue; PackCommand CommandPckt = new PackCommand(); CommandPckt.PacketElements = CommandPacketElems; TransmitCommand SendCmd = new TransmitCommand(); SendCmd.DataPacket = CommandPckt.CommandPack; SendCmd.RemoteSystemName = NetParams.RemoteSystemName; SendCmd.SendCommand(); #endregion #region Code for receiving result from remote system ReceiveResult ReceiveData = new ReceiveResult(); ResultPacketElement ResultElements = ReceiveData.GetResultPacket(); IResult Result = new ExecutionResult(); if (ResultElements.Header == int.Parse(ConfigurationSettings.AppSettings["ResultHeader"])) { Result = ResultElements.ActualResult; } else { throw(new ApplicationException("Corrupted Result")); } #endregion return(Result); }
public void PackCommandSupportsDisablingRules(string disabledRules, bool isEnabled) { // Arrange var package = PackageUtility.CreatePackage("A", "1.0-alpha"); var builder = new StringBuilder(); var console = new Mock <IConsole>(); console.Setup(c => c.WriteWarning(It.IsAny <string>(), It.IsAny <object[]>())).Callback <string, object[]>((text, p) => builder.AppendFormat(text, p)); console.Setup(c => c.WriteWarning(It.IsAny <bool>(), It.IsAny <string>(), It.IsAny <object[]>())).Callback <bool, string, object[]>((b, text, p) => builder.AppendFormat(text, p)); var packCommand = new PackCommand { Console = console.Object, Rules = Enumerable.Empty <IPackageRule>() }; packCommand.DisableRules = disabledRules; // Act packCommand.AnalyzePackage(package); // Assert if (isEnabled) { Assert.Equal(@"1 issue(s) found with package 'A'.Issue: Use semantic versioningDescription: Version ""1.0-alpha"" does not follow semantic versioning guidelines.Solution: Update your nuspec file or use the AssemblyInformationalVersion assembly attribute to specify a semantic version as described at http://semver.org. ", builder.ToString()); } else { Assert.Equal(string.Empty, builder.ToString()); } }
public void Check_GeneratePackedLibraryFiles() { //arrange string[] expected_ConsolidatedUsings = new string[] { "System", "System.Collections", "System.Linq", "System.Text" }; var srcdocList = new List <SrcDoc>(); srcdocList.Add(new SrcDoc() { SyntaxTree = CSharpSyntaxTree.ParseText(helloworld1_cs) }); srcdocList.Add(new SrcDoc() { SyntaxTree = CSharpSyntaxTree.ParseText(helloworld2_cs) }); //act var packcmd = new PackCommand(new PackOptions()); var targetfiles = packcmd.GenerateTargetFilesList(srcdocList); packcmd.GeneratePackedLibraryFiles(targetfiles); targetfiles.Should().HaveCount(1); targetfiles.ElementAt(0).GlobalUsings.Select(_ => _.ToString()) .Should().BeEquivalentTo(expected_ConsolidatedUsings); }
public void Given_nuget_alias_It_finds_the_entry_point_dll_and_command_name_and_put_in_setting_file() { TestAsset helloWorldAsset = _testAssetsManager .CopyTestAsset("PortableTool") .WithSource() .WithProjectChanges(project => { XNamespace ns = project.Root.Name.Namespace; XElement propertyGroup = project.Root.Elements(ns + "PropertyGroup").First(); propertyGroup.Elements("TargetFramework").First().SetValue("targetframeworkAlias"); XElement conditionPropertyGroup = new XElement("PropertyGroup"); project.Root.Add(conditionPropertyGroup); conditionPropertyGroup.SetAttributeValue("Condition", "'$(TargetFramework)' == 'targetframeworkAlias'"); conditionPropertyGroup.SetElementValue("TargetFrameworkIdentifier", ".NETCoreApp"); conditionPropertyGroup.SetElementValue("TargetFrameworkVersion", "v3.1"); conditionPropertyGroup.SetElementValue("TargetFrameworkMoniker", ".NETCoreApp,Version=v3.1"); }); _testRoot = helloWorldAsset.TestRoot; var packCommand = new PackCommand(Log, helloWorldAsset.TestRoot); var result = packCommand.Execute(); result.Should().Pass(); var nugetPackage = packCommand.GetNuGetPackage(); AssertFiles(nugetPackage); }
static void Main(string[] args) { try { int exitcode = CommandLine.Parser.Default .ParseArguments <PackOptions, DummyOptions>(args) .MapResult( (PackOptions opts) => { var val = new PackOptionsValidator(null).Validate(opts).WriteWhenNotValid(Console.Error); if (val.IsValid == false) { return(val.NonZeroExit()); } var cmd = new PackCommand(opts); return(cmd.Execute()); }, (DummyOptions opts) => 255, (parserErrors) => 255 ); Exit(exitcode); } catch (Exception ex) { Console.Error.WriteLine(ex.ToString()); Exit(255); } }
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 HasServiceableFlagWhenArgumentPassed() { var testInstance = TestAssetsManager .CreateTestInstance("TestLibraryWithConfiguration") .WithBuildArtifacts() .WithLockFiles(); var testProject = Path.Combine(testInstance.Path, "project.json"); var packCommand = new PackCommand(testProject, configuration: "Debug", serviceable: true); var result = packCommand.Execute(); result.Should().Pass(); var outputDir = new DirectoryInfo(Path.Combine(testInstance.Path, "bin", "Debug")); outputDir.Should().Exist(); outputDir.Should().HaveFiles(new[] { "TestLibraryWithConfiguration.1.0.0.nupkg", "TestLibraryWithConfiguration.1.0.0.symbols.nupkg" }); var outputPackage = Path.Combine(outputDir.FullName, "TestLibraryWithConfiguration.1.0.0.nupkg"); var zip = ZipFile.Open(outputPackage, ZipArchiveMode.Read); zip.Entries.Should().Contain(e => e.FullName == "TestLibraryWithConfiguration.nuspec"); var manifestReader = new StreamReader(zip.Entries.First(e => e.FullName == "TestLibraryWithConfiguration.nuspec").Open()); var nuspecXml = XDocument.Parse(manifestReader.ReadToEnd()); var node = nuspecXml.Descendants().Single(e => e.Name.LocalName == "serviceable"); Assert.Equal("true", node.Value); }
public void PackAddsCorrectFilesForProjectsWithOutputNameSpecified() { var testInstance = TestAssetsManager .CreateTestInstance("LibraryWithOutputAssemblyName") .WithLockFiles(); var cmd = new PackCommand(Path.Combine(testInstance.TestRoot, Project.FileName)); cmd.Execute().Should().Pass(); var outputPackage = Path.Combine(testInstance.TestRoot, "bin", "Debug", "LibraryWithOutputAssemblyName.1.0.0.nupkg"); File.Exists(outputPackage).Should().BeTrue(outputPackage); var zip = ZipFile.Open(outputPackage, ZipArchiveMode.Read); zip.Entries.Should().Contain(e => e.FullName == "lib/netstandard1.5/MyLibrary.dll"); var symbolsPackage = Path.Combine(testInstance.TestRoot, "bin", "Debug", "LibraryWithOutputAssemblyName.1.0.0.symbols.nupkg"); File.Exists(symbolsPackage).Should().BeTrue(symbolsPackage); zip = ZipFile.Open(symbolsPackage, ZipArchiveMode.Read); zip.Entries.Should().Contain(e => e.FullName == "lib/netstandard1.5/MyLibrary.dll"); zip.Entries.Should().Contain(e => e.FullName == "lib/netstandard1.5/MyLibrary.pdb"); }
public void PackCommandDefaultFiltersRemovesManifestAndPackageFiles() { // Arrange var files = GetPackageFiles( @"x:\packagefiles\some-file\1.txt", @"x:\packagefiles\folder\test.nupkg", @"x:\packagefiles\folder\should-not-exclude\test.nupkg.html", @"x:\packagefiles\test.nuspec", @"x:\packagefiles\test.nuspec.bkp", @"x:\packagefiles\subdir\foo.nuspec" ); // Act var packCommand = new PackCommand { BasePath = @"x:\packagefiles\", NoDefaultExcludes = false }; packCommand.ExcludeFiles(files); // Assert Assert.AreEqual(3, files.Count); Assert.AreEqual(files[0].Path, @"x:\packagefiles\some-file\1.txt"); Assert.AreEqual(files[1].Path, @"x:\packagefiles\folder\should-not-exclude\test.nupkg.html"); Assert.AreEqual(files[2].Path, @"x:\packagefiles\test.nuspec.bkp"); }
public void It_uses_customized_PackagedShimOutputRootDirectory(bool multiTarget, string targetFramework) { string shimoutputPath = Path.Combine(TestContext.Current.TestExecutionDirectory, "shimoutput"); TestAsset helloWorldAsset = _testAssetsManager .CopyTestAsset("PortableTool", "PackagedShimOutputRootDirectory" + multiTarget.ToString(), identifier: multiTarget.ToString() + targetFramework) .WithSource() .WithProjectChanges(project => { XNamespace ns = project.Root.Name.Namespace; XElement propertyGroup = project.Root.Elements(ns + "PropertyGroup").First(); propertyGroup.Add(new XElement(ns + "PackAsToolShimRuntimeIdentifiers", "win-x64;osx.10.12-x64")); propertyGroup.Add(new XElement(ns + "ToolCommandName", _customToolCommandName)); propertyGroup.Add(new XElement(ns + "PackagedShimOutputRootDirectory", shimoutputPath)); }) .WithTargetFrameworkOrFrameworks(targetFramework, multiTarget); _testRoot = helloWorldAsset.TestRoot; var packCommand = new PackCommand(Log, helloWorldAsset.TestRoot); packCommand.Execute().Should().Pass(); string windowShimPath = Path.Combine(shimoutputPath, $"shims/{targetFramework}/win-x64/{_customToolCommandName}.exe"); File.Exists(windowShimPath).Should().BeTrue($"Shim {windowShimPath} should exist"); string osxShimPath = Path.Combine(shimoutputPath, $"shims/{targetFramework}/osx.10.12-x64/{_customToolCommandName}"); File.Exists(osxShimPath).Should().BeTrue($"Shim {osxShimPath} should exist"); }
public void ExcludeFilesDoesNotUseDefaultExcludesIfDisabled() { // Arrange var files = GetPackageFiles( @"p:\some-file\test.txt", @"p:\some-file\should-not-be-removed\ext\sample.nupkg", @"p:\some-file\manifest.nuspec", @"p:\some-file\should-not-be-removed\.hgignore", @"p:\some-file\should-be-removed\file.ext" ); // Act var packCommand = new PackCommand { BasePath = @"p:\some-file", NoDefaultExcludes = true }; packCommand.Exclude.Add(@"**\*.ext"); packCommand.ExcludeFiles(files); // Assert Assert.AreEqual(3, files.Count); Assert.AreEqual(files[0].Path, @"p:\some-file\test.txt"); Assert.AreEqual(files[1].Path, @"p:\some-file\should-not-be-removed\ext\sample.nupkg"); Assert.AreEqual(files[2].Path, @"p:\some-file\should-not-be-removed\.hgignore"); }
public void It_contains_shim_with_no_build(bool multiTarget, string targetFramework) { var testAsset = CreateTestAsset(multiTarget, nameof(It_contains_shim_with_no_build) + multiTarget + targetFramework, targetFramework); var buildCommand = new BuildCommand(testAsset); buildCommand.Execute().Should().Pass(); var packCommand = new PackCommand(Log, testAsset.TestRoot); packCommand.Execute("/p:NoBuild=true").Should().Pass(); var nugetPackage = packCommand.GetNuGetPackage(); using (var nupkgReader = new PackageArchiveReader(nugetPackage)) { IEnumerable <NuGetFramework> supportedFrameworks = nupkgReader.GetSupportedFrameworks(); supportedFrameworks.Should().NotBeEmpty(); foreach (NuGetFramework framework in supportedFrameworks) { var allItems = nupkgReader.GetToolItems().SelectMany(i => i.Items).ToList(); allItems.Should().Contain($"tools/{framework.GetShortFolderName()}/any/shims/win-x64/{_customToolCommandName}.exe", "Name should be the same as the command name even customized"); allItems.Should().Contain($"tools/{framework.GetShortFolderName()}/any/shims/osx.10.12-x64/{_customToolCommandName}", "RID should be the exact match of the RID in the property, even Apphost only has version of win, osx and linux"); } } }
public void It_should_fail_with_error_message(string targetFrameworkProperty, string targetFramework, string expectedErrorResourceName) { TestAsset helloWorldAsset = _testAssetsManager .CopyTestAsset("PortableTool", "PackNonSupportedTFM") .WithSource() .WithProjectChanges(project => { XNamespace ns = project.Root.Name.Namespace; XElement propertyGroup = project.Root.Elements(ns + "PropertyGroup").First(); propertyGroup.Element(ns + "TargetFramework").Remove(); propertyGroup.Add(new XElement(ns + targetFrameworkProperty, targetFramework)); }); helloWorldAsset.Restore(Log); var packCommand = new PackCommand(Log, helloWorldAsset.TestRoot); CommandResult result = packCommand.Execute(); result.ExitCode.Should().NotBe(0); // walk around attribute requires static string expectedErrorMessage = Strings.ResourceManager.GetString(expectedErrorResourceName); result.StdOut.Should().Contain(expectedErrorMessage); }
public async Task Pack_project_blazor_contents() { var asset = await Create.NetstandardWorkspaceCopy(); var packageName = Path.GetFileNameWithoutExtension(asset.Directory.GetFiles("*.csproj").First().Name); var console = new TestConsole(); await PackCommand.Do(new PackOptions(asset.Directory, enableBlazor : true), console); asset.Directory .GetFiles() .Should() .Contain(f => f.Name.Contains("nupkg")); var dotnet = new Dotnet(asset.Directory); var result = await dotnet.ToolInstall(packageName, asset.Directory, new PackageSource(asset.Directory.FullName)); var exe = Path.Combine(asset.Directory.FullName, packageName); var tool = new WorkspaceServer.WorkspaceFeatures.PackageTool(packageName, asset.Directory); await tool.Prepare(); var wasmDirectory = await tool.LocateWasmAsset(); wasmDirectory.Should().NotBeNull(); }
public override void Send(List <Guid> usersID, PackCommand pack) { foreach (var user in usersID) { Send(user, pack); } }
public void CompatibleFrameworksInPackage() { TestProject testProject = new() { Name = "TestPackage", TargetFrameworks = "netstandard2.0;net5.0", }; string sourceCode = @" namespace PackageValidationTests { public class First { public void test() { } #if NETSTANDARD2_0 public void test(string test) { } #endif } }"; testProject.SourceFiles.Add("Hello.cs", sourceCode); TestAsset asset = _testAssetsManager.CreateTestProject(testProject, testProject.Name); PackCommand packCommand = new PackCommand(Log, Path.Combine(asset.TestRoot, testProject.Name)); var result = packCommand.Execute(); Assert.Equal(string.Empty, result.StdErr); Package package = NupkgParser.CreatePackage(packCommand.GetNuGetPackage(), null); new CompatibleFrameworkInPackageValidator(string.Empty, null, _log).Validate(package); Assert.NotEmpty(_log.errors); // TODO: add asserts for assembly and header metadata. Assert.Contains("CP0002 Member 'PackageValidationTests.First.test(string)' exists on the left but not on the right", _log.errors); }
public static async Task <(DirectoryInfo, string)> CreateTool(TestConsole console) { var asset = await Create.NetstandardWorkspaceCopy(); await PackCommand.Do(new PackOptions(asset.Directory), console); return(asset.Directory, asset.Name); }
public void TestDotnetPack() { var packCommand = new PackCommand(TestDirectory, output: OutputDirectory); packCommand.Execute() .Should() .Pass(); }