public void It_publishes_as_framework_dependent_by_default() { var testAsset = _testAssetsManager .CopyTestAsset("WebApp") .WithSource(); var args = new[] { "-p:Configuration=Release" }; var restoreCommand = new RestoreCommand(testAsset); restoreCommand .Execute(args) .Should() .Pass(); var command = new PublishCommand(testAsset); command .Execute(args) .Should() .Pass(); var publishDirectory = command.GetOutputDirectory(targetFramework: "netcoreapp2.0", configuration: "Release"); publishDirectory.Should().NotHaveSubDirectories(); publishDirectory.Should().OnlyHaveFiles(new[] { "web.config", "web.deps.json", "web.dll", "web.pdb", "web.PrecompiledViews.dll", "web.PrecompiledViews.pdb", "web.runtimeconfig.json", }); }
public void It_publishes_all_satellites_when_not_filtered() { var testProject = new TestProject() { Name = "PublishSatelliteAssemblies", TargetFrameworks = "netcoreapp2.0", IsExe = true, IsSdkProject = true }; testProject.PackageReferences.Add(new TestPackageReference("System.Spatial", "5.8.3")); var testProjectInstance = _testAssetsManager.CreateTestProject(testProject) .Restore(Log, testProject.Name); var publishCommand = new PublishCommand(Log, Path.Combine(testProjectInstance.TestRoot, testProject.Name)); var publishResult = publishCommand.Execute(); publishResult.Should().Pass(); var publishDirectory = publishCommand.GetOutputDirectory(targetFramework: testProject.TargetFrameworks); publishDirectory.Should().OnlyHaveFiles(new[] { "de/System.Spatial.resources.dll", "es/System.Spatial.resources.dll", "fr/System.Spatial.resources.dll", "it/System.Spatial.resources.dll", "ja/System.Spatial.resources.dll", "ko/System.Spatial.resources.dll", "ru/System.Spatial.resources.dll", "zh-Hans/System.Spatial.resources.dll", "zh-Hant/System.Spatial.resources.dll", "System.Spatial.dll", $"{testProject.Name}.dll", $"{testProject.Name}.pdb", $"{testProject.Name}.deps.json", $"{testProject.Name}.runtimeconfig.json" }); }
public void It_publishes_the_app_config_if_necessary() { var testAsset = _testAssetsManager .CopyTestAsset("DesktopNeedsBindingRedirects") .WithSource() .Restore(Log); PublishCommand publishCommand = new PublishCommand(Log, testAsset.TestRoot); publishCommand .Execute() .Should() .Pass(); DirectoryInfo publishDirectory = publishCommand.GetOutputDirectory("net452", "Debug", "win7-x86"); publishDirectory.Should().HaveFiles(new[] { "DesktopNeedsBindingRedirects.exe", "DesktopNeedsBindingRedirects.exe.config" }); }
public void It_creates_readytorun_images_for_all_assemblies_except_excluded_ones(string targetFramework) { var projectName = "CrossgenTest2"; var testProject = CreateTestProjectForR2RTesting( targetFramework, projectName, "ClassLib"); testProject.AdditionalProperties["PublishReadyToRun"] = "True"; testProject.AdditionalItems["PublishReadyToRunExclude"] = "Classlib.dll"; var testProjectInstance = _testAssetsManager.CreateTestProject(testProject); var publishCommand = new PublishCommand(Log, Path.Combine(testProjectInstance.Path, testProject.Name)); publishCommand.Execute().Should().Pass(); DirectoryInfo publishDirectory = publishCommand.GetOutputDirectory( targetFramework, "Debug", testProject.RuntimeIdentifier); var mainProjectDll = Path.Combine(publishDirectory.FullName, $"{projectName}.dll"); var classLibDll = Path.Combine(publishDirectory.FullName, $"ClassLib.dll"); if (!RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { publishDirectory.Should().NotHaveFiles(new[] { GetPDBFileName(mainProjectDll), GetPDBFileName(classLibDll), }); } DoesImageHaveR2RInfo(mainProjectDll).Should().BeTrue(); DoesImageHaveR2RInfo(classLibDll).Should().BeFalse(); publishDirectory.Should().HaveFile("System.Private.CoreLib.dll"); // self-contained }
public void No_runtime_files_6_0() { var testProject = new TestProject() { Name = "SingleFileTest", TargetFrameworks = "net6.0", IsExe = true, }; var testAsset = _testAssetsManager.CreateTestProject(testProject); var publishCommand = new PublishCommand(testAsset); publishCommand .Execute(PublishSingleFile, RuntimeIdentifier) .Should() .Pass(); string[] expectedFiles = { $"{testProject.Name}{Constants.ExeSuffix}", $"{testProject.Name}.pdb" }; GetPublishDirectory(publishCommand, "net6.0") .Should() .OnlyHaveFiles(expectedFiles); }
public void It_errors_when_publishing_single_file_lib() { var testProject = new TestProject() { Name = "ClassLib", TargetFrameworks = "netstandard2.0", IsSdkProject = true, IsExe = false, }; var testAsset = _testAssetsManager.CreateTestProject(testProject); var publishCommand = new PublishCommand(Log, Path.Combine(testAsset.TestRoot, testProject.Name)); publishCommand.Execute(PublishSingleFile, RuntimeIdentifier) .Should() .Fail() .And .HaveStdOutContaining(Strings.CannotHaveSingleFileWithoutExecutable) .And .NotHaveStdOutContaining(Strings.CanOnlyHaveSingleFileWithNetCoreApp); }
public void Publish_WithBlazorWebAssemblyLoadAllGlobalizationData_SetsICUDataMode() { // Arrange var testAppName = "BlazorHosted"; var testInstance = CreateAspNetSdkTestAsset(testAppName); testInstance.WithProjectChanges((project) => { var ns = project.Root.Name.Namespace; var itemGroup = new XElement(ns + "PropertyGroup"); itemGroup.Add(new XElement("BlazorWebAssemblyLoadAllGlobalizationData", true)); project.Root.Add(itemGroup); }); var publishCommand = new PublishCommand(testInstance, "blazorhosted"); publishCommand.WithWorkingDirectory(testInstance.TestRoot); publishCommand.Execute("/bl") .Should().Pass(); var publishDirectory = publishCommand.GetOutputDirectory(DefaultTfm).ToString(); var bootJsonPath = Path.Combine(publishDirectory, "wwwroot", "_framework", "blazor.boot.json"); var bootJsonData = ReadBootJsonData(bootJsonPath); bootJsonData.icuDataMode.Should().Be(ICUDataMode.All); var runtime = bootJsonData.resources.runtime; runtime.Should().ContainKey("dotnet.wasm"); runtime.Should().ContainKey("dotnet.timezones.blat"); runtime.Should().ContainKey("icudt.dat"); runtime.Should().ContainKey("icudt_EFIGS.dat"); new FileInfo(Path.Combine(publishDirectory, "wwwroot", "_framework", "dotnet.wasm")).Should().Exist(); new FileInfo(Path.Combine(publishDirectory, "wwwroot", "_framework", "icudt.dat")).Should().Exist(); new FileInfo(Path.Combine(publishDirectory, "wwwroot", "_framework", "icudt_CJK.dat")).Should().Exist(); new FileInfo(Path.Combine(publishDirectory, "wwwroot", "_framework", "icudt_EFIGS.dat")).Should().Exist(); new FileInfo(Path.Combine(publishDirectory, "wwwroot", "_framework", "icudt_no_CJK.dat")).Should().Exist(); }
public void ILLink_runs_and_creates_linked_app(string targetFramework, bool referenceClassLibAsPackage) { var projectName = "HelloWorld"; var referenceProjectName = "ClassLibForILLink"; var rid = EnvironmentInfo.GetCompatibleRid(targetFramework); var testProject = CreateTestProjectForILLinkTesting(targetFramework, projectName, referenceProjectName, referenceClassLibAsPackage); string[] restoreArgs = { $"/p:RuntimeIdentifier={rid}", "/p:SelfContained=true" }; var testAsset = _testAssetsManager.CreateTestProject(testProject, identifier: targetFramework + referenceClassLibAsPackage) .WithProjectChanges(project => EnableNonFrameworkTrimming(project)); var publishCommand = new PublishCommand(Log, Path.Combine(testAsset.TestRoot, testProject.Name)); publishCommand.Execute($"/p:RuntimeIdentifier={rid}", $"/p:SelfContained=true", "/p:PublishTrimmed=true").Should().Pass(); var publishDirectory = publishCommand.GetOutputDirectory(targetFramework: targetFramework, runtimeIdentifier: rid).FullName; var intermediateDirectory = publishCommand.GetIntermediateDirectory(targetFramework: targetFramework, runtimeIdentifier: rid).FullName; var linkedDirectory = Path.Combine(intermediateDirectory, "linked"); Directory.Exists(linkedDirectory).Should().BeTrue(); var linkedDll = Path.Combine(linkedDirectory, $"{projectName}.dll"); var publishedDll = Path.Combine(publishDirectory, $"{projectName}.dll"); var unusedDll = Path.Combine(publishDirectory, $"{referenceProjectName}.dll"); var unusedFrameworkDll = Path.Combine(publishDirectory, $"{unusedFrameworkAssembly}.dll"); // Intermediate assembly is kept by linker and published, but not unused assemblies File.Exists(linkedDll).Should().BeTrue(); File.Exists(publishedDll).Should().BeTrue(); File.Exists(unusedDll).Should().BeFalse(); File.Exists(unusedFrameworkDll).Should().BeFalse(); var depsFile = Path.Combine(publishDirectory, $"{projectName}.deps.json"); DoesDepsFileHaveAssembly(depsFile, projectName).Should().BeTrue(); DoesDepsFileHaveAssembly(depsFile, referenceProjectName).Should().BeFalse(); DoesDepsFileHaveAssembly(depsFile, unusedFrameworkAssembly).Should().BeFalse(); }
public void It_publishes_successfully(bool generatePackageOnBuild, bool packAsTool) { Console.WriteLine(generatePackageOnBuild.ToString() + packAsTool.ToString()); TestAsset testAsset = _testAssetsManager .CopyTestAsset("HelloWorld", identifier: generatePackageOnBuild.ToString() + packAsTool.ToString()) .WithSource() .WithProjectChanges((projectPath, project) => { XNamespace ns = project.Root.Name.Namespace; XElement propertyGroup = project.Root.Elements(ns + "PropertyGroup").First(); propertyGroup.Add(new XElement(ns + "GeneratePackageOnBuild", generatePackageOnBuild.ToString())); propertyGroup.Add(new XElement(ns + "PackAsTool", packAsTool.ToString())); }); var publishCommand = new PublishCommand(testAsset); CommandResult result = publishCommand.Execute(); result.Should() .Pass(); }
public void It_creates_readytorun_symbols_when_switch_is_used(string targetFramework) { var projectName = "CrossgenTest3"; var testProject = CreateTestProjectForR2RTesting( EnvironmentInfo.GetCompatibleRid(targetFramework), projectName, "ClassLib"); testProject.AdditionalProperties["PublishReadyToRun"] = "True"; testProject.AdditionalProperties["PublishReadyToRunEmitSymbols"] = "True"; var testProjectInstance = _testAssetsManager.CreateTestProject(testProject); var publishCommand = new PublishCommand(Log, Path.Combine(testProjectInstance.Path, testProject.Name)); publishCommand.Execute().Should().Pass(); DirectoryInfo publishDirectory = publishCommand.GetOutputDirectory( targetFramework, "Debug", testProject.RuntimeIdentifier); var mainProjectDll = Path.Combine(publishDirectory.FullName, $"{projectName}.dll"); var classLibDll = Path.Combine(publishDirectory.FullName, $"ClassLib.dll"); if (!RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { publishDirectory.Should().HaveFiles(new[] { GetPDBFileName(mainProjectDll), GetPDBFileName(classLibDll), }); } DoesImageHaveR2RInfo(mainProjectDll).Should().BeTrue(); DoesImageHaveR2RInfo(classLibDll).Should().BeTrue(); publishDirectory.Should().HaveFile("System.Private.CoreLib.dll"); // self-contained }
public void It_generates_a_single_file_including_pdbs(string targetFramework) { var testProject = new TestProject() { Name = "SingleFileTest", TargetFrameworks = targetFramework, IsExe = true, }; var testAsset = _testAssetsManager.CreateTestProject(testProject); var publishCommand = new PublishCommand(testAsset); publishCommand .Execute(PublishSingleFile, RuntimeIdentifier, IncludeAllContent, IncludePdb) .Should() .Pass(); string[] expectedFiles = { $"{testProject.Name}{Constants.ExeSuffix}" }; GetPublishDirectory(publishCommand, targetFramework) .Should() .OnlyHaveFiles(expectedFiles); }
public void It_publishes_windows_Forms_app_with_warning() { var targetFramework = "net6.0-windows"; TestProject testProject = new TestProject() { Name = "WinformsWarnPresentPassTest", TargetFrameworks = targetFramework }; testProject.AdditionalProperties["UseWindowsForms"] = "true"; testProject.AdditionalProperties["SelfContained"] = "true"; testProject.AdditionalProperties["RuntimeIdentifier"] = "win-x64"; var testAsset = _testAssetsManager.CreateTestProject(testProject); var publishCommand = new PublishCommand(testAsset); publishCommand.Execute($"/p:PublishTrimmed=true") .Should() .Pass() .And .HaveStdOutContaining("NETSDK1167"); }
public void Publish_CopiesStaticWebAssetsToDestinationFolder_PublishSingleFile() { var tfm = "net5.0"; var testAsset = "RazorAppWithPackageAndP2PReference"; var projectDirectory = CreateAspNetSdkTestAsset(testAsset, overrideTfm: tfm) .WithProjectChanges((path, project) => { if (path.Contains("AppWithPackageAndP2PReference")) { var ns = project.Root.Name.Namespace; var itemGroup = new XElement(ns + "PropertyGroup"); itemGroup.Add(new XElement("RuntimeIdentifier", "win-x64")); project.Root.Add(itemGroup); } }); var publish = new PublishCommand(Log, Path.Combine(projectDirectory.TestRoot, "AppWithPackageAndP2PReference")); publish.Execute("/p:PublishSingleFile=true", "/p:ReferenceLocallyBuiltPackages=true").Should().Pass(); var publishOutputPathWithRID = publish.GetOutputDirectory(tfm, "Debug", "win-x64").ToString(); new FileInfo(Path.Combine(publishOutputPathWithRID, "wwwroot", "_content", "ClassLibrary", "ClassLibrary.bundle.scp.css")).Should().Exist(); new FileInfo(Path.Combine(publishOutputPathWithRID, "wwwroot", "_content", "ClassLibrary", "js", "project-transitive-dep.js")).Should().Exist(); new FileInfo(Path.Combine(publishOutputPathWithRID, "wwwroot", "_content", "ClassLibrary", "js", "project-transitive-dep.v4.js")).Should().Exist(); new FileInfo(Path.Combine(publishOutputPathWithRID, "wwwroot", "_content", "AnotherClassLib", "css", "site.css")).Should().Exist(); new FileInfo(Path.Combine(publishOutputPathWithRID, "wwwroot", "_content", "AnotherClassLib", "js", "project-direct-dep.js")).Should().Exist(); new FileInfo(Path.Combine(publishOutputPathWithRID, "wwwroot", "_content", "PackageLibraryDirectDependency", "css", "site.css")).Should().Exist(); new FileInfo(Path.Combine(publishOutputPathWithRID, "wwwroot", "_content", "PackageLibraryDirectDependency", "js", "pkg-direct-dep.js")).Should().Exist(); new FileInfo(Path.Combine(publishOutputPathWithRID, "wwwroot", "_content", "PackageLibraryTransitiveDependency", "js", "pkg-transitive-dep.js")).Should().Exist(); new FileInfo(Path.Combine(publishOutputPathWithRID, "wwwroot", "AppWithPackageAndP2PReference.styles.css")).Should().Exist(); // Validate that static web assets don't get published as content too on their regular path new FileInfo(Path.Combine(publishOutputPathWithRID, "wwwroot", "js", "project-transitive-dep.js")).Should().NotExist(); new FileInfo(Path.Combine(publishOutputPathWithRID, "wwwroot", "js", "project-transitive-dep.v4.js")).Should().NotExist(); // Validate that the manifest never gets copied new FileInfo(Path.Combine(publishOutputPathWithRID, "AppWithPackageAndP2PReference.StaticWebAssets.xml")).Should().NotExist(); }
public void It_only_publishes_selected_ResourceLanguages(string tfm) { var testProject = new TestProject() { Name = "PublishFilteredSatelliteAssemblies", TargetFrameworks = tfm, IsExe = true, }; testProject.PackageReferences.Add(new TestPackageReference("System.Spatial", "5.8.3")); testProject.AdditionalProperties.Add("SatelliteResourceLanguages", "en-US;it;fr"); var testProjectInstance = _testAssetsManager.CreateTestProject(testProject); var publishCommand = new PublishCommand(Log, Path.Combine(testProjectInstance.TestRoot, testProject.Name)); var publishResult = publishCommand.Execute(); publishResult.Should().Pass(); var publishDirectory = publishCommand.GetOutputDirectory(targetFramework: testProject.TargetFrameworks); var files = new List <string>() { "it/System.Spatial.resources.dll", "fr/System.Spatial.resources.dll", "System.Spatial.dll", $"{testProject.Name}.dll", $"{testProject.Name}.pdb", $"{testProject.Name}.deps.json", $"{testProject.Name}.runtimeconfig.json" }; if (tfm == "netcoreapp3.0" && !RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { files.Add($"{testProject.Name}{Constants.ExeSuffix}"); } publishDirectory.Should().OnlyHaveFiles(files); }
public void It_collects_Trimmer_SingleFile_ReadyToRun_publishing_properties(string targetFramework) { Type loggerType = typeof(LogTelemetryToStdOutForTest); var TelemetryTestLogger = new[] { $"/Logger:{loggerType.FullName},{loggerType.GetTypeInfo().Assembly.Location}" }; var testProject = CreateTestProject(targetFramework, "TrimmedR2RSingleFileProject", true, true, true); var testProjectInstance = _testAssetsManager.CreateTestProject(testProject); var publishCommand = new PublishCommand(Log, Path.Combine(testProjectInstance.Path, testProject.Name)); string s = publishCommand.Execute(TelemetryTestLogger).StdOut;//.Should() s.Should().Contain( "{\"EventName\":\"PublishProperties\",\"Properties\":{\"PublishReadyToRun\":\"True\",\"PublishTrimmed\":\"True\",\"PublishSingleFile\":\"True\"}"); s.Should().Contain( "{\"EventName\":\"ReadyToRun\",\"Properties\":{\"PublishReadyToRunUseCrossgen2\":\"null\",\"Crossgen2PackVersion\":\"null\""); s.Should().Contain( "\"FailedCount\":\"0\""); s.Should().MatchRegex( "\"CompileListCount\":\"[1-9]\\d?\""); // Do not hardcode number of assemblies being compiled here, due to ILTrimmer }
public void Publish_NoBuild_PublishesBundleToTheRightLocation() { var testAsset = "RazorComponentApp"; var projectDirectory = CreateAspNetSdkTestAsset(testAsset); var build = new BuildCommand(projectDirectory); build.WithWorkingDirectory(projectDirectory.Path); var buildResult = build.Execute("/bl"); buildResult.Should().Pass(); var publish = new PublishCommand(Log, projectDirectory.TestRoot); publish.Execute("/p:NoBuild=true").Should().Pass(); var publishOutputPath = publish.GetOutputDirectory(DefaultTfm, "Debug").ToString(); new FileInfo(Path.Combine(publishOutputPath, "wwwroot", "ComponentApp.styles.css")).Should().Exist(); new FileInfo(Path.Combine(publishOutputPath, "wwwroot", "_content", "ComponentApp", "Components", "Pages", "Index.razor.rz.scp.css")).Should().NotExist(); new FileInfo(Path.Combine(publishOutputPath, "wwwroot", "_content", "ComponentApp", "Components", "Pages", "Counter.razor.rz.scp.css")).Should().NotExist(); }
private void PushPackage(string packagePath, string source, string apiKey) { var packageServer = new PackageServer(source, "NuGet Command Line"); // Push the package to the server var package = new ZipPackage(packagePath); bool complete = false; //HACK no pretty source name, as they have made the call to CommandLineUtility.GetSourceDisplayName(source) internal Console.WriteLine("Pushing {0} to {1}", package.GetFullName(), source); try { using (Stream stream = package.GetStream()) { packageServer.PushPackage(apiKey, stream, 60000); } } catch { if (!complete) { Console.WriteLine(); } throw; } // Publish the package on the server var cmd = new PublishCommand(); cmd.Console = Console; cmd.Source = source; cmd.Arguments.AddRange(new List <string> { package.Id, package.Version.ToString(), apiKey }); cmd.Execute(); }
public void Publish_DeterministicAcrossBuilds_WhenNoSourcesChange() { // Arrange var testAppName = "BlazorWasmWithLibrary"; var testInstance = _testAssetsManager.CopyTestAsset(testAppName) .WithSource(); var publishCommand = new PublishCommand(Log, Path.Combine(testInstance.TestRoot, "blazorwasm")); publishCommand.Execute("/p:ServiceWorkerAssetsManifest=service-worker-assets.js").Should().Pass(); var publishOutputDirectory = publishCommand.GetOutputDirectory("net5.0").ToString(); var serviceWorkerFile = Path.Combine(publishOutputDirectory, "wwwroot", "serviceworkers", "my-service-worker.js"); var version = File.ReadAllLines(serviceWorkerFile).Last(); var match = Regex.Match(version, "\\/\\* Manifest version: (.{8}) \\*\\/"); match.Success.Should().BeTrue(); match.Groups.Count.Should().Be(2); match.Groups[1].Value.Should().NotBeNull(); var capture = match.Groups[1].Value; // Act && Assert publishCommand = new PublishCommand(Log, Path.Combine(testInstance.TestRoot, "blazorwasm")); publishCommand.Execute("/p:ServiceWorkerAssetsManifest=service-worker-assets.js").Should().Pass(); var updatedVersion = File.ReadAllLines(serviceWorkerFile).Last(); var updatedMatch = Regex.Match(updatedVersion, "\\/\\* Manifest version: (.{8}) \\*\\/"); updatedMatch.Success.Should().BeTrue(); updatedMatch.Groups.Count.Should().Be(2); updatedMatch.Groups[1].Value.Should().NotBeNull(); var updatedCapture = updatedMatch.Groups[1].Value; updatedCapture.Should().Be(capture); }
public void Publish_self_contained_app_with_dot_in_the_name() { var targetFramework = "netcoreapp2.0"; var rid = EnvironmentInfo.GetCompatibleRid(targetFramework); TestProject testProject = new TestProject() { Name = "Hello.World", IsSdkProject = true, TargetFrameworks = targetFramework, RuntimeIdentifier = rid, IsExe = true, }; testProject.SourceFiles["Program.cs"] = @" using System; public static class Program { public static void Main() { Console.WriteLine(""Hello from a netcoreapp2.0.!""); } } "; var testProjectInstance = _testAssetsManager.CreateTestProject(testProject); testProjectInstance.Restore(Log, testProject.Name); var publishCommand = new PublishCommand(Log, Path.Combine(testProjectInstance.TestRoot, testProject.Name)); publishCommand.Execute().Should().Pass(); var publishDirectory = publishCommand.GetOutputDirectory( targetFramework: targetFramework, runtimeIdentifier: rid); publishDirectory.Should().HaveFile($"Hello.World{Constants.ExeSuffix}"); }
public void Warnings_are_generated_even_with_analyzers_disabled(string targetFramework) { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { var projectName = "WarningAppWithPublishAotAnalyzersDisabled"; var rid = EnvironmentInfo.GetCompatibleRid(targetFramework); // PublishAot enables the EnableAotAnalyzer, EnableTrimAnalyzer and EnableSingleFileAnalyzer // only if they don't have a predefined value var testProject = CreateTestProjectWithAnalysisWarnings(targetFramework, projectName, true); testProject.AdditionalProperties["PublishAot"] = "true"; testProject.AdditionalProperties["EnableAotAnalyzer"] = "false"; testProject.AdditionalProperties["EnableTrimAnalyzer"] = "false"; testProject.AdditionalProperties["EnableSingleFileAnalyzer"] = "false"; testProject.AdditionalProperties["SuppressTrimAnalysisWarnings"] = "false"; testProject.AdditionalProperties["RuntimeIdentifier"] = rid; var testAsset = _testAssetsManager.CreateTestProject(testProject); var publishCommand = new PublishCommand(Log, Path.Combine(testAsset.TestRoot, testProject.Name)); publishCommand .Execute() .Should().Pass() .And.HaveStdOutContaining("warning IL3050") .And.HaveStdOutContaining("warning IL2026"); var publishDirectory = publishCommand.GetOutputDirectory(targetFramework: targetFramework, runtimeIdentifier: rid); var publishedExe = Path.Combine(publishDirectory.FullName, $"{testProject.Name}{Constants.ExeSuffix}"); // The exe exist and should be native File.Exists(publishedExe).Should().BeTrue(); IsNativeImage(publishedExe).Should().BeTrue(); var command = new RunExeCommand(Log, publishedExe) .Execute().Should().Pass() .And.HaveStdOutContaining("Hello world"); } }
public void It_creates_readytorun_images_for_all_assemblies_except_excluded_ones(string targetFramework) { var projectName = "CrossgenTest2"; var testProject = CreateTestProjectForR2RTesting( EnvironmentInfo.GetCompatibleRid(targetFramework), projectName, "ClassLib"); testProject.AdditionalProperties["ReadyToRun"] = "True"; testProject.AdditionalItems["ReadyToRunExclude"] = "Classlib.dll"; var testProjectInstance = _testAssetsManager.CreateTestProject(testProject) .Restore(Log, testProject.Name); var publishCommand = new PublishCommand(Log, Path.Combine(testProjectInstance.Path, testProject.Name)); publishCommand.Execute("/v:n").Should().Pass(); DirectoryInfo publishDirectory = publishCommand.GetOutputDirectory( targetFramework, "Debug", EnvironmentInfo.GetCompatibleRid(targetFramework)); var mainProjectDll = Path.Combine(publishDirectory.FullName, $"{projectName}.dll"); var classLibDll = Path.Combine(publishDirectory.FullName, $"ClassLib.dll"); if (!RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { publishDirectory.Should().NotHaveFiles(new[] { GetPDBFileName(mainProjectDll), GetPDBFileName(classLibDll), }); } DoesImageHaveR2RInfo(mainProjectDll).ToString().Should().Be(true.ToString()); DoesImageHaveR2RInfo(classLibDll).ToString().Should().Be(false.ToString()); }
public void It_publishes_all_satellites_when_not_filtered() { var testProject = new TestProject() { Name = "PublishSatelliteAssemblies", TargetFrameworks = ToolsetInfo.CurrentTargetFramework, IsExe = true, }; testProject.PackageReferences.Add(new TestPackageReference("System.Spatial", "5.8.3")); var testProjectInstance = _testAssetsManager.CreateTestProject(testProject); var publishCommand = new PublishCommand(testProjectInstance); var publishResult = publishCommand.Execute(); publishResult.Should().Pass(); var publishDirectory = publishCommand.GetOutputDirectory(targetFramework: testProject.TargetFrameworks); publishDirectory.Should().OnlyHaveFiles(new[] { "de/System.Spatial.resources.dll", "es/System.Spatial.resources.dll", "fr/System.Spatial.resources.dll", "it/System.Spatial.resources.dll", "ja/System.Spatial.resources.dll", "ko/System.Spatial.resources.dll", "ru/System.Spatial.resources.dll", "zh-Hans/System.Spatial.resources.dll", "zh-Hant/System.Spatial.resources.dll", "System.Spatial.dll", $"{testProject.Name}.dll", $"{testProject.Name}.pdb", $"{testProject.Name}.deps.json", $"{testProject.Name}.runtimeconfig.json", $"{testProject.Name}{EnvironmentInfo.ExecutableExtension}" }); }
public void It_publishes_projects_with_filter_and_rid() { string project = "SimpleDependencies"; var rid = RuntimeEnvironment.GetRuntimeIdentifier(); TestAsset simpleDependenciesAsset = _testAssetsManager .CopyTestAsset(project) .WithSource() .Restore("", $"/p:RuntimeIdentifier={rid}"); string filterProjDir = _testAssetsManager.GetAndValidateTestProjectDirectory("StoreManifests"); string manifestFile = Path.Combine(filterProjDir, "NewtonsoftFilterProfile.xml"); PublishCommand publishCommand = new PublishCommand(Stage0MSBuild, simpleDependenciesAsset.TestRoot); publishCommand .Execute($"/p:RuntimeIdentifier={rid}", $"/p:TargetManifestFiles={manifestFile}") .Should() .Pass(); DirectoryInfo publishDirectory = publishCommand.GetOutputDirectory(runtimeIdentifier: rid); publishDirectory.Should().HaveFiles(new[] { $"{project}.dll", $"{project}.pdb", $"{project}.deps.json", $"{project}.runtimeconfig.json", "System.Collections.NonGeneric.dll", $"{FileConstants.DynamicLibPrefix}coreclr{FileConstants.DynamicLibSuffix}" }); publishDirectory.Should().NotHaveFiles(new[] { "Newtonsoft.Json.dll", "System.Runtime.Serialization.Primitives.dll" }); //TODO: Enable testing the run once dotnet host has the notion of looking up shared packages }
public void ILLink_defaults_keep_nonframework(string targetFramework) { var projectName = "HelloWorld"; var referenceProjectName = "ClassLibForILLink"; var rid = EnvironmentInfo.GetCompatibleRid(targetFramework); var testProject = CreateTestProjectForILLinkTesting(targetFramework, projectName, referenceProjectName); string[] restoreArgs = { $"/p:RuntimeIdentifier={rid}", "/p:SelfContained=true" }; var testAsset = _testAssetsManager.CreateTestProject(testProject) .Restore(Log, testProject.Name, restoreArgs); var publishCommand = new PublishCommand(Log, Path.Combine(testAsset.TestRoot, testProject.Name)); publishCommand.Execute("/v:n", $"/p:RuntimeIdentifier={rid}", $"/p:SelfContained=true", "/p:PublishTrimmed=true").Should().Pass(); var publishDirectory = publishCommand.GetOutputDirectory(targetFramework: targetFramework, runtimeIdentifier: rid).FullName; var intermediateDirectory = publishCommand.GetIntermediateDirectory(targetFramework: targetFramework, runtimeIdentifier: rid).FullName; var linkedDirectory = Path.Combine(intermediateDirectory, "linked"); Directory.Exists(linkedDirectory).Should().BeTrue(); var linkedDll = Path.Combine(linkedDirectory, $"{projectName}.dll"); var publishedDll = Path.Combine(publishDirectory, $"{projectName}.dll"); var unusedDll = Path.Combine(publishDirectory, $"{referenceProjectName}.dll"); var unusedFrameworkDll = Path.Combine(publishDirectory, $"{unusedFrameworkAssembly}.dll"); File.Exists(linkedDll).Should().BeTrue(); File.Exists(publishedDll).Should().BeTrue(); File.Exists(unusedDll).Should().BeTrue(); File.Exists(unusedFrameworkDll).Should().BeFalse(); var depsFile = Path.Combine(publishDirectory, $"{projectName}.deps.json"); DoesDepsFileHaveAssembly(depsFile, projectName).Should().BeTrue(); DoesDepsFileHaveAssembly(depsFile, referenceProjectName).Should().BeTrue(); DoesDepsFileHaveAssembly(depsFile, unusedFrameworkAssembly).Should().BeFalse(); }
private void PublishAppWithLibraryAndRid(bool selfContained, out DirectoryInfo publishDirectory, out string runtimeIdentifier) { runtimeIdentifier = DotNet.PlatformAbstractions.RuntimeEnvironment.GetRuntimeIdentifier(); var testAsset = _testAssetsManager .CopyTestAsset("AppWithLibraryAndRid", $"PublishAppWithLibraryAndRid{selfContained}") .WithSource(); var projectPath = Path.Combine(testAsset.TestRoot, "App"); var msbuildArgs = new List <string>() { $"/p:RuntimeIdentifier={runtimeIdentifier}", $"/p:TestRuntimeIdentifier={runtimeIdentifier}", $"/p:SelfContained={selfContained}" }; if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { // .NET Core 2.1.0 packages don't support latest versions of OS X, so roll forward to the // latest patch which does msbuildArgs.Add("/p:TargetLatestRuntimePatch=true"); } var restoreCommand = new RestoreCommand(Log, projectPath, "App.csproj"); restoreCommand .Execute(msbuildArgs.ToArray()) .Should() .Pass(); var publishCommand = new PublishCommand(Log, projectPath); publishCommand .Execute(msbuildArgs.ToArray()) .Should().Pass(); publishDirectory = publishCommand.GetOutputDirectory("netcoreapp2.1", runtimeIdentifier: runtimeIdentifier); }
/// <summary> /// Called to execute a specific supported verb. /// </summary> /// <param name="verbName">Name of the verb to execute.</param> /// <param name="verbInstance">Instance of the options for the verb.</param> static void ExecuteVerb(string verbName, object verbInstance) { // Make sure that we have a verb instance if (verbInstance == null) { // No verb instance available, so parsing command line arguments failed, nothing more to do return; } // Determine the verb that was executed switch (verbName) { case PublishOptions.VERB_NAME: var verbOptions = (PublishOptions)verbInstance; var command = new PublishCommand(verbOptions); command.Execute(); return; default: // Unknown verb return; } }
public void PrepareForILLink_can_set_TrimMode(string targetFramework) { var projectName = "HelloWorld"; var referenceProjectName = "ClassLibForILLink"; var rid = EnvironmentInfo.GetCompatibleRid(targetFramework); var testProject = CreateTestProjectForILLinkTesting(targetFramework, projectName, referenceProjectName); var testAsset = _testAssetsManager.CreateTestProject(testProject) .WithProjectChanges(project => SetTrimMode(project, referenceProjectName, "link")); var publishCommand = new PublishCommand(Log, Path.Combine(testAsset.TestRoot, testProject.Name)); publishCommand.Execute($"/p:RuntimeIdentifier={rid}", $"/p:SelfContained=true", "/p:PublishTrimmed=true").Should().Pass(); var publishDirectory = publishCommand.GetOutputDirectory(targetFramework: targetFramework, runtimeIdentifier: rid).FullName; var publishedDll = Path.Combine(publishDirectory, $"{projectName}.dll"); var unusedTrimModeLinkDll = Path.Combine(publishDirectory, $"{referenceProjectName}.dll"); File.Exists(publishedDll).Should().BeTrue(); // Check that the unused "link" assembly was removed. File.Exists(unusedTrimModeLinkDll).Should().BeFalse(); }
private void TestLibProjectPublishing_Internal(string projectName, bool isSelfContained, string targetFramework) { var testProject = CreateTestProjectForR2RTesting( EnvironmentInfo.GetCompatibleRid(targetFramework), projectName, "ClassLib", isExeProject: false); testProject.AdditionalProperties["PublishReadyToRun"] = "True"; if (isSelfContained) { testProject.AdditionalProperties["SelfContained"] = "True"; } var testProjectInstance = _testAssetsManager.CreateTestProject(testProject); var publishCommand = new PublishCommand(Log, Path.Combine(testProjectInstance.Path, testProject.Name)); publishCommand.Execute().Should().Pass(); DirectoryInfo publishDirectory = publishCommand.GetOutputDirectory( targetFramework, "Debug", testProject.RuntimeIdentifier); DoesImageHaveR2RInfo(Path.Combine(publishDirectory.FullName, $"{projectName}.dll")).Should().BeTrue(); DoesImageHaveR2RInfo(Path.Combine(publishDirectory.FullName, "ClassLib.dll")).Should().BeTrue(); if (isSelfContained) { publishDirectory.Should().HaveFile("System.Private.CoreLib.dll"); } else { publishDirectory.Should().NotHaveFile("System.Private.CoreLib.dll"); } }
public void It_publishes_portable_apps_to_the_publish_folder_and_the_app_should_run(string targetFramework) { if (!EnvironmentInfo.SupportsTargetFramework(targetFramework)) { return; } var helloWorldAsset = _testAssetsManager .CopyTestAsset("HelloWorld", identifier: targetFramework) .WithSource() .WithTargetFramework(targetFramework); var publishCommand = new PublishCommand(helloWorldAsset); var publishResult = publishCommand.Execute(); publishResult.Should().Pass(); var publishDirectory = publishCommand.GetOutputDirectory(targetFramework); var outputDirectory = publishDirectory.Parent; var filesPublished = new[] { "HelloWorld.dll", "HelloWorld.pdb", "HelloWorld.deps.json", "HelloWorld.runtimeconfig.json" }; outputDirectory.Should().HaveFiles(filesPublished); publishDirectory.Should().HaveFiles(filesPublished); new DotnetCommand(Log, Path.Combine(publishDirectory.FullName, "HelloWorld.dll")) .Execute() .Should() .Pass() .And .HaveStdOutContaining("Hello World!"); }
public void Publish_WithInvariantGlobalizationEnabled_DoesNotCopyGlobalizationData() { // Arrange var testAppName = "BlazorWasmMinimal"; var testInstance = _testAssetsManager.CopyTestAsset(testAppName) .WithSource(); testInstance.WithProjectChanges((project) => { var ns = project.Root.Name.Namespace; var itemGroup = new XElement(ns + "PropertyGroup"); itemGroup.Add(new XElement("InvariantGlobalization", true)); project.Root.Add(itemGroup); }); var publishCommand = new PublishCommand(Log, testInstance.TestRoot); publishCommand.Execute().Should().Pass(); var publishOutputDirectory = publishCommand.GetOutputDirectory("net5.0").ToString(); var bootJsonPath = Path.Combine(publishOutputDirectory.ToString(), "wwwroot", "_framework", "blazor.boot.json"); var bootJsonData = ReadBootJsonData(bootJsonPath); bootJsonData.icuDataMode.Should().Be(ICUDataMode.Invariant); var runtime = bootJsonData.resources.runtime; runtime.Should().ContainKey("dotnet.wasm"); runtime.Should().NotContainKey("icudt.dat"); runtime.Should().NotContainKey("icudt_EFIGS.dat"); new FileInfo(Path.Combine(publishOutputDirectory, "wwwroot", "_framework", "dotnet.wasm")).Should().Exist(); new FileInfo(Path.Combine(publishOutputDirectory, "wwwroot", "_framework", "icudt.dat")).Should().NotExist(); new FileInfo(Path.Combine(publishOutputDirectory, "wwwroot", "_framework", "icudt_CJK.dat")).Should().NotExist(); new FileInfo(Path.Combine(publishOutputDirectory, "wwwroot", "_framework", "icudt_EFIGS.dat")).Should().NotExist(); new FileInfo(Path.Combine(publishOutputDirectory, "wwwroot", "_framework", "icudt_no_CJK.dat")).Should().NotExist(); }
private void PushPackage(string packagePath, string source, string apiKey) { var gallery = new GalleryServer(source); // Push the package to the server var package = new ZipPackage(packagePath); bool complete = false; gallery.ProgressAvailable += (sender, e) => { Console.Write("\r" + "Pushing: {0}", e.PercentComplete); if (e.PercentComplete == 100) { Console.WriteLine(); complete = true; } }; Console.WriteLine("Pushing {0} to {1}", package.GetFullName(), _sourceProvider.GetDisplayName(source)); try { using (Stream stream = package.GetStream()) { gallery.CreatePackage(apiKey, stream); } } catch { if (!complete) { Console.WriteLine(); } throw; } // Publish the package on the server var cmd = new PublishCommand(_sourceProvider); cmd.Console = Console; cmd.Source = source; cmd.Arguments = new List<string> { package.Id, package.Version.ToString(), apiKey }; cmd.Execute(); }