public void BuildProjectWithReferences_GeneratesJsonManifestAndCopiesItToOutputFolder() { var testAsset = "RazorAppWithPackageAndP2PReference"; ProjectDirectory = CreateAspNetSdkTestAsset(testAsset); var build = new BuildCommand(ProjectDirectory, "AppWithPackageAndP2PReference"); build.Execute().Should().Pass(); var intermediateOutputPath = build.GetIntermediateDirectory(DefaultTfm, "Debug").ToString(); var outputPath = build.GetOutputDirectory(DefaultTfm, "Debug").ToString(); // GenerateStaticWebAssetsManifest should generate the manifest file. var path = Path.Combine(intermediateOutputPath, "StaticWebAssets.build.json"); new FileInfo(path).Should().Exist(); AssertManifest( StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(path)), LoadBuildManifest()); // GenerateStaticWebAssetsManifest should copy the file to the output folder. var finalPath = Path.Combine(outputPath, "AppWithPackageAndP2PReference.staticwebassets.json"); new FileInfo(finalPath).Should().Exist(); AssertManifest( StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(finalPath)), LoadBuildManifest()); AssertBuildAssets( StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(finalPath)), outputPath, intermediateOutputPath); }
public void StaticWebAssets_PublishMinimal_Works() { // Arrange // Minimal has no project references, service worker etc. This is pretty close to the project template. var testAsset = "BlazorWasmMinimal"; ProjectDirectory = CreateAspNetSdkTestAsset(testAsset); File.WriteAllText(Path.Combine(ProjectDirectory.TestRoot, "App.razor.css"), "h1 { font-size: 16px; }"); File.WriteAllText(Path.Combine(ProjectDirectory.TestRoot, "wwwroot", "appsettings.development.json"), "{}"); var publish = new PublishCommand(ProjectDirectory); publish.WithWorkingDirectory(ProjectDirectory.TestRoot); var publishResult = publish.Execute("/bl"); publishResult.Should().Pass(); var publishPath = publish.GetOutputDirectory(DefaultTfm).ToString(); var intermediateOutputPath = publish.GetIntermediateDirectory(DefaultTfm, "Debug").ToString(); // GenerateStaticWebAssetsManifest should generate the manifest file. var path = Path.Combine(intermediateOutputPath, "staticwebassets.publish.json"); new FileInfo(path).Should().Exist(); var manifest = StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(path)); AssertManifest(manifest, LoadPublishManifest()); AssertPublishAssets( StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(path)), publishPath, intermediateOutputPath); }
public void Publish_PublishesBundleToTheRightLocation() { var testAsset = "RazorComponentApp"; ProjectDirectory = CreateAspNetSdkTestAsset(testAsset); Directory.CreateDirectory(Path.Combine(ProjectDirectory.TestRoot, "wwwroot")); File.WriteAllText(Path.Combine(ProjectDirectory.TestRoot, "wwwroot", "ComponentApp.lib.module.js"), "console.log('Hello world!');"); var publish = new PublishCommand(ProjectDirectory); publish.WithWorkingDirectory(ProjectDirectory.TestRoot); var publishResult = publish.Execute("/bl"); publishResult.Should().Pass(); var outputPath = publish.GetOutputDirectory(DefaultTfm).ToString(); var intermediateOutputPath = publish.GetIntermediateDirectory(DefaultTfm, "Debug").ToString(); var path = Path.Combine(intermediateOutputPath, "staticwebassets.publish.json"); new FileInfo(path).Should().Exist(); var manifest = StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(path)); AssertManifest(manifest, LoadPublishManifest()); AssertPublishAssets( StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(path)), outputPath, intermediateOutputPath); }
public void BuildProjectWithReferences_CorrectlyBundlesScopedCssFiles() { var testAsset = "RazorAppWithPackageAndP2PReference"; ProjectDirectory = CreateAspNetSdkTestAsset(testAsset); var build = new BuildCommand(ProjectDirectory, "AppWithPackageAndP2PReference"); build.WithWorkingDirectory(ProjectDirectory.TestRoot); build.Execute("/bl").Should().Pass(); var intermediateOutputPath = build.GetIntermediateDirectory(DefaultTfm, "Debug").ToString(); var outputPath = build.GetOutputDirectory(DefaultTfm, "Debug").ToString(); // GenerateStaticWebAssetsManifest should copy the file to the output folder. var finalPath = Path.Combine(outputPath, "AppWithPackageAndP2PReference.staticwebassets.runtime.json"); new FileInfo(finalPath).Should().Exist(); AssertManifest( StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(Path.Combine(intermediateOutputPath, "staticwebassets.build.json"))), LoadBuildManifest()); AssertBuildAssets( StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(Path.Combine(intermediateOutputPath, "staticwebassets.build.json"))), outputPath, intermediateOutputPath); var appBundle = new FileInfo(Path.Combine(intermediateOutputPath, "scopedcss", "bundle", "AppWithPackageAndP2PReference.styles.css")); appBundle.Should().Exist(); appBundle.Should().Contain("_content/ClassLibrary/ClassLibrary.bundle.scp.css"); appBundle.Should().Contain("_content/PackageLibraryDirectDependency/PackageLibraryDirectDependency.bundle.scp.css"); }
public void StaticWebAssets_Build_Hosted_Works() { // Arrange var testAppName = "BlazorHosted"; ProjectDirectory = CreateAspNetSdkTestAsset(testAppName); var build = new BuildCommand(ProjectDirectory, "blazorhosted"); build.WithWorkingDirectory(ProjectDirectory.TestRoot); var buildResult = build.Execute("/bl"); buildResult.Should().Pass(); var outputPath = build.GetOutputDirectory(DefaultTfm).ToString(); var intermediateOutputPath = build.GetIntermediateDirectory(DefaultTfm, "Debug").ToString(); // GenerateStaticWebAssetsManifest should generate the manifest file. var path = Path.Combine(intermediateOutputPath, "staticwebassets.build.json"); new FileInfo(path).Should().Exist(); var manifest = StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(path)); AssertManifest(manifest, LoadBuildManifest()); // GenerateStaticWebAssetsManifest should copy the file to the output folder. var finalPath = Path.Combine(outputPath, "blazorhosted.staticwebassets.runtime.json"); new FileInfo(finalPath).Should().Exist(); AssertBuildAssets( StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(path)), outputPath, intermediateOutputPath); }
public void StaticWebAssets_Publish_DoesNotIncludeXmlDocumentationFiles_AsAssets() { // Arrange var testAppName = "BlazorHosted"; ProjectDirectory = CreateAspNetSdkTestAsset(testAppName); // Check that static web assets is correctly configured by setting up a css file to triger css isolation. // The list of publish files should not include bundle.scp.css and should include blazorwasm.styles.css File.WriteAllText(Path.Combine(ProjectDirectory.TestRoot, "blazorwasm", "App.razor.css"), "h1 { font-size: 16px; }"); var publish = new PublishCommand(ProjectDirectory, "blazorhosted"); publish.WithWorkingDirectory(ProjectDirectory.TestRoot); var publishResult = publish.Execute("/p:GenerateDocumentationFile=true", "/bl"); publishResult.Should().Pass(); var publishPath = publish.GetOutputDirectory(DefaultTfm).ToString(); var intermediateOutputPath = publish.GetIntermediateDirectory(DefaultTfm, "Debug").ToString(); // GenerateStaticWebAssetsManifest should generate the manifest file. var path = Path.Combine(intermediateOutputPath, "staticwebassets.publish.json"); new FileInfo(path).Should().Exist(); var manifest = StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(path)); AssertManifest(manifest, LoadPublishManifest()); AssertPublishAssets( StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(path)), publishPath, intermediateOutputPath); }
public void Build_GeneratesJsonManifestAndCopiesItToOutputFolder() { var expectedManifest = LoadBuildManifest(); var testAsset = "RazorComponentApp"; ProjectDirectory = CreateAspNetSdkTestAsset(testAsset); var build = new BuildCommand(ProjectDirectory); build.WithWorkingDirectory(ProjectDirectory.TestRoot); build.Execute("/bl").Should().Pass(); var intermediateOutputPath = build.GetIntermediateDirectory(DefaultTfm, "Debug").ToString(); var outputPath = build.GetOutputDirectory(DefaultTfm, "Debug").ToString(); // GenerateStaticWebAssetsManifest should generate the manifest file. var path = Path.Combine(intermediateOutputPath, "StaticWebAssets.build.json"); new FileInfo(path).Should().Exist(); var manifest = StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(path)); AssertManifest(manifest, expectedManifest); // GenerateStaticWebAssetsManifest should copy the file to the output folder. var finalPath = Path.Combine(outputPath, "ComponentApp.staticwebassets.json"); new FileInfo(finalPath).Should().Exist(); AssertManifest(StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(finalPath)), expectedManifest); AssertBuildAssets(StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(finalPath)), outputPath, intermediateOutputPath); }
public void JsModules_CanHaveDifferentBuildAndPublishModules() { // Arrange var testAsset = "BlazorWasmMinimal"; ProjectDirectory = CreateAspNetSdkTestAsset(testAsset); File.WriteAllText(Path.Combine(ProjectDirectory.TestRoot, "wwwroot", "blazorwasm-minimal.lib.module.js"), "console.log('Publish initializer')"); File.WriteAllText(Path.Combine(ProjectDirectory.TestRoot, "wwwroot", "blazorwasm-minimal.lib.module.build.js"), "console.log('Build initializer')"); ProjectDirectory.WithProjectChanges(document => { document.Root.Add(new XElement("ItemGroup", new XElement("Content", new XAttribute("Update", "wwwroot\\blazorwasm-minimal.lib.module.build.js"), new XAttribute("CopyToPublishDirectory", "Never"), new XAttribute("TargetPath", "wwwroot\\blazorwasm-minimal.lib.module.js")))); }); var publish = new PublishCommand(ProjectDirectory); publish.WithWorkingDirectory(ProjectDirectory.TestRoot); var publishResult = publish.Execute("/bl"); publishResult.Should().Pass(); var outputPath = publish.GetOutputDirectory(DefaultTfm).ToString(); var intermediateOutputPath = publish.GetIntermediateDirectory(DefaultTfm, "Debug").ToString(); var path = Path.Combine(intermediateOutputPath, "staticwebassets.publish.json"); new FileInfo(path).Should().Exist(); var manifest = StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(path)); AssertManifest(manifest, LoadPublishManifest()); var buildLibrary = GetLibraryInitializer(Path.Combine(intermediateOutputPath, "blazor.boot.json")); var publishLibrary = GetLibraryInitializer(Path.Combine(intermediateOutputPath, "blazor.publish.boot.json")); publishLibrary.GetString().Should().NotBe(buildLibrary.GetString()); new FileInfo(Path.Combine(outputPath, "wwwroot", "blazorwasm-minimal.modules.json")).Should().NotExist(); var lib = new FileInfo(Path.Combine(outputPath, "wwwroot", "blazorwasm-minimal.lib.module.js")); lib.Should().Exist(); var wwwrootPublishLibrary = GetLibraryInitializer(Path.Combine(outputPath, "wwwroot", "_framework", "blazor.boot.json")); publishLibrary.GetString().Should().Be(wwwrootPublishLibrary.GetString()); AssertPublishAssets( StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(path)), outputPath, intermediateOutputPath);
public void StaticWebAssets_HostedApp_ReferencingNetStandardLibrary_Works() { // Arrange var testAppName = "BlazorHosted"; ProjectDirectory = CreateAspNetSdkTestAsset(testAppName); ProjectDirectory.WithProjectChanges((project, document) => { if (Path.GetFileNameWithoutExtension(project) == "blazorwasm") { document.Descendants("TargetFramework").Single().ReplaceNodes("net5"); } if (Path.GetFileNameWithoutExtension(project) == "RazorClassLibrary") { document.Descendants("TargetFramework").Single().ReplaceNodes("netstandard2.1"); document.Descendants("PropertyGroup").First().Add(new XElement("RazorLangVersion", "3.0")); } if (Path.GetFileNameWithoutExtension(project) == "classlibrarywithsatelliteassemblies") { document.Descendants("TargetFramework").Single().ReplaceNodes("netstandard2.1"); document.Descendants("PropertyGroup").First().Add(new XElement("RazorLangVersion", "3.0")); } }); var build = new BuildCommand(ProjectDirectory, "blazorhosted"); build.WithWorkingDirectory(ProjectDirectory.TestRoot); var buildResult = build.Execute("/bl"); buildResult.Should().Pass(); var outputPath = build.GetOutputDirectory(DefaultTfm).ToString(); var intermediateOutputPath = build.GetIntermediateDirectory(DefaultTfm, "Debug").ToString(); // GenerateStaticWebAssetsManifest should generate the manifest file. var path = Path.Combine(intermediateOutputPath, "staticwebassets.build.json"); new FileInfo(path).Should().Exist(); var manifest = StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(path)); AssertManifest(manifest, LoadBuildManifest()); // GenerateStaticWebAssetsManifest should copy the file to the output folder. var finalPath = Path.Combine(outputPath, "blazorhosted.staticwebassets.runtime.json"); new FileInfo(finalPath).Should().Exist(); AssertBuildAssets( StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(path)), outputPath, intermediateOutputPath); }
public void StaticWebAssets_BackCompatibilityPublish_Hosted_Works() { // Arrange var testAppName = "BlazorHosted"; ProjectDirectory = CreateAspNetSdkTestAsset(testAppName); ProjectDirectory.WithProjectChanges((project, document) => { if (Path.GetFileNameWithoutExtension(project) == "blazorwasm") { document.Descendants("TargetFramework").Single().ReplaceNodes("net5"); } if (Path.GetFileNameWithoutExtension(project) == "RazorClassLibrary") { document.Descendants("TargetFramework").Single().ReplaceNodes("netstandard2.1"); document.Descendants("PropertyGroup").First().Add(new XElement("RazorLangVersion", "3.0")); } if (Path.GetFileNameWithoutExtension(project) == "classlibrarywithsatelliteassemblies") { document.Descendants("TargetFramework").Single().ReplaceNodes("netstandard2.1"); document.Descendants("PropertyGroup").First().Add(new XElement("RazorLangVersion", "3.0")); } }); // Check that static web assets is correctly configured by setting up a css file to triger css isolation. // The list of publish files should not include bundle.scp.css and should include blazorwasm.styles.css File.WriteAllText(Path.Combine(ProjectDirectory.TestRoot, "blazorwasm", "App.razor.css"), "h1 { font-size: 16px; }"); var publish = new PublishCommand(ProjectDirectory, "blazorhosted"); publish.WithWorkingDirectory(ProjectDirectory.TestRoot); var publishResult = publish.Execute("/bl"); publishResult.Should().Pass(); var publishPath = publish.GetOutputDirectory(DefaultTfm).ToString(); var intermediateOutputPath = publish.GetIntermediateDirectory(DefaultTfm, "Debug").ToString(); // GenerateStaticWebAssetsManifest should generate the manifest file. var path = Path.Combine(intermediateOutputPath, "staticwebassets.publish.json"); new FileInfo(path).Should().Exist(); var manifest = StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(path)); AssertManifest(manifest, LoadPublishManifest()); AssertPublishAssets( StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(path)), publishPath, intermediateOutputPath); }
public void Publish60Hosted_Works() { // Arrange var testAsset = "BlazorWasmHosted60"; var targetFramework = "net6.0"; ProjectDirectory = CreateAspNetSdkTestAsset(testAsset); var publish = new PublishCommand(ProjectDirectory, "Server"); publish.Execute() .Should() .Pass() .And.NotHaveStdOutContaining("warning IL"); var publishOutputDirectory = publish.GetOutputDirectory(targetFramework); publishOutputDirectory.Should().HaveFiles(new[] { $"{testAsset}.Client.dll", $"{testAsset}.Shared.dll", "wwwroot/index.html", "wwwroot/_framework/blazor.boot.json", "wwwroot/_framework/blazor.webassembly.js", "wwwroot/_framework/dotnet.wasm", "wwwroot/_framework/System.Text.Json.dll", $"wwwroot/_framework/{testAsset}.Client.dll", $"wwwroot/_framework/{testAsset}.Shared.dll", "wwwroot/css/app.css", // Verify compression works "wwwroot/_framework/dotnet.wasm.br", $"wwwroot/_framework/{testAsset}.Client.dll.br", "wwwroot/_framework/System.Text.Json.dll.br" }); var intermediateOutputPath = publish.GetIntermediateDirectory(targetFramework, "Debug").ToString(); // GenerateStaticWebAssetsManifest should generate the manifest file. var path = Path.Combine(intermediateOutputPath, "staticwebassets.publish.json"); new FileInfo(path).Should().Exist(); var manifest = StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(path)); AssertManifest(manifest, LoadPublishManifest()); AssertPublishAssets( StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(path)), publishOutputDirectory.FullName, intermediateOutputPath); }
public void Publish_DoesNotGenerateManifestJson_IncludesJSModulesOnBlazorBootJsonManifest() { // Arrange var testAsset = "BlazorWasmMinimal"; ProjectDirectory = CreateAspNetSdkTestAsset(testAsset); File.WriteAllText(Path.Combine(ProjectDirectory.TestRoot, "wwwroot", "blazorwasm-minimal.lib.module.js"), "console.log('Hello initializer')"); var publish = new PublishCommand(ProjectDirectory); publish.WithWorkingDirectory(ProjectDirectory.TestRoot); var publishResult = publish.Execute("/bl"); publishResult.Should().Pass(); var outputPath = publish.GetOutputDirectory(DefaultTfm).ToString(); var intermediateOutputPath = publish.GetIntermediateDirectory(DefaultTfm, "Debug").ToString(); var path = Path.Combine(intermediateOutputPath, "staticwebassets.publish.json"); new FileInfo(path).Should().Exist(); var manifest = StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(path)); AssertManifest(manifest, LoadPublishManifest()); var blazorBootJson = new FileInfo(Path.Combine(intermediateOutputPath, "blazor.publish.boot.json")); blazorBootJson.Should().Exist(); var contents = JsonSerializer.Deserialize <JsonDocument>(blazorBootJson.OpenRead()); contents.RootElement.TryGetProperty("resources", out var resources).Should().BeTrue(); resources.TryGetProperty("libraryInitializers", out var initializers).Should().BeTrue(); initializers.TryGetProperty("blazorwasm-minimal.lib.module.js", out var hash).Should().BeTrue(); Convert.TryFromBase64String(hash.GetString().Substring("SHA256-".Length), new byte[256], out _).Should().BeTrue(); new FileInfo(Path.Combine(outputPath, "wwwroot", "blazorwasm-minimal.modules.json")).Should().NotExist(); var lib = new FileInfo(Path.Combine(outputPath, "wwwroot", "blazorwasm-minimal.lib.module.js")); lib.Should().Exist(); AssertPublishAssets( StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(path)), outputPath, intermediateOutputPath); }
public void PublishProjectWithReferences_IncorporatesInitializersFromClassLibrariesAndPublishesAssetsToTheRightLocation() { var testAsset = "RazorAppWithPackageAndP2PReference"; ProjectDirectory = CreateAspNetSdkTestAsset(testAsset); var restore = new RestoreCommand(Log, Path.Combine(ProjectDirectory.TestRoot, "AppWithPackageAndP2PReference")); restore.Execute().Should().Pass(); CreateFile("console.log('Hello world AnotherClassLib')", "AnotherClassLib", "wwwroot", "AnotherClassLib.lib.module.js"); // Notice that it does not follow the pattern $(PackageId).lib.module.js CreateFile("console.log('Hello world ClassLibrary')", "ClassLibrary", "wwwroot", "AnotherClassLib.lib.module.js"); var publish = new PublishCommand(Log, Path.Combine(ProjectDirectory.TestRoot, "AppWithPackageAndP2PReference")); publish.WithWorkingDirectory(ProjectDirectory.Path); publish.Execute("/bl").Should().Pass(); var intermediateOutputPath = publish.GetIntermediateDirectory(DefaultTfm, "Debug").ToString(); var outputPath = publish.GetOutputDirectory(DefaultTfm, "Debug").ToString(); var path = Path.Combine(intermediateOutputPath, "staticwebassets.build.json"); AssertManifest( StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(path)), LoadBuildManifest()); var finalPath = Path.Combine(intermediateOutputPath, "staticwebassets.publish.json"); AssertManifest( StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(finalPath)), LoadPublishManifest()); AssertPublishAssets( StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(finalPath)), outputPath, intermediateOutputPath); var file = new FileInfo(Path.Combine(outputPath, "wwwroot", "AppWithPackageAndP2PReference.modules.json")); file.Should().Exist(); file.Should().Contain("_content/AnotherClassLib/AnotherClassLib.lib.module.js"); file.Should().NotContain("_content/ClassLibrary/AnotherClassLib.lib.module.js"); }
public void ScopedCss_IsBackwardsCompatible_WithPreviousVersions() { var testAsset = "RazorAppWithPackageAndP2PReference"; ProjectDirectory = CreateAspNetSdkTestAsset(testAsset) .WithProjectChanges((project, document) => { if (Path.GetFileName(project) == "AnotherClassLib.csproj") { document.Descendants("TargetFramework").Single().ReplaceNodes("net5.0"); } if (Path.GetFileName(project) == "ClassLibrary.csproj") { document.Descendants("TargetFramework").Single().ReplaceNodes("net5.0"); } }); var build = new BuildCommand(ProjectDirectory, "AppWithPackageAndP2PReference"); build.WithWorkingDirectory(ProjectDirectory.TestRoot); build.Execute("/bl").Should().Pass(); var intermediateOutputPath = build.GetIntermediateDirectory(DefaultTfm, "Debug").ToString(); var outputPath = build.GetOutputDirectory(DefaultTfm, "Debug").ToString(); // GenerateStaticWebAssetsManifest should copy the file to the output folder. var finalPath = Path.Combine(outputPath, "AppWithPackageAndP2PReference.staticwebassets.runtime.json"); new FileInfo(finalPath).Should().Exist(); AssertManifest( StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(Path.Combine(intermediateOutputPath, "staticwebassets.build.json"))), LoadBuildManifest()); AssertBuildAssets( StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(Path.Combine(intermediateOutputPath, "staticwebassets.build.json"))), outputPath, intermediateOutputPath); var appBundle = new FileInfo(Path.Combine(intermediateOutputPath, "scopedcss", "bundle", "AppWithPackageAndP2PReference.styles.css")); appBundle.Should().Exist(); appBundle.Should().Contain("_content/ClassLibrary/ClassLibrary.bundle.scp.css"); appBundle.Should().Contain("_content/PackageLibraryDirectDependency/PackageLibraryDirectDependency.bundle.scp.css"); }
public void PublishProjectWithReferences_GeneratesPublishJsonManifestAndCopiesPublishAssets() { var testAsset = "RazorAppWithPackageAndP2PReference"; ProjectDirectory = CreateAspNetSdkTestAsset(testAsset); var restore = new RestoreCommand(Log, Path.Combine(ProjectDirectory.TestRoot, "AppWithPackageAndP2PReference")); restore.Execute().Should().Pass(); var publish = new PublishCommand(Log, Path.Combine(ProjectDirectory.TestRoot, "AppWithPackageAndP2PReference")); publish.WithWorkingDirectory(ProjectDirectory.Path); publish.Execute("/bl").Should().Pass(); var intermediateOutputPath = publish.GetIntermediateDirectory(DefaultTfm, "Debug").ToString(); var publishPath = publish.GetOutputDirectory(DefaultTfm, "Debug").ToString(); // GenerateStaticWebAssetsManifest should generate the manifest file. var path = Path.Combine(intermediateOutputPath, "StaticWebAssets.build.json"); new FileInfo(path).Should().Exist(); AssertManifest( StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(path)), LoadBuildManifest()); // GenerateStaticWebAssetsManifest should copy the file to the output folder. var finalPath = Path.Combine(publishPath, "AppWithPackageAndP2PReference.staticwebassets.json"); new FileInfo(finalPath).Should().NotExist(); // GenerateStaticWebAssetsPublishManifest should generate the publish manifest file. var intermediatePublishManifestPath = Path.Combine(intermediateOutputPath, "StaticWebAssets.publish.json"); new FileInfo(path).Should().Exist(); AssertManifest( StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(intermediatePublishManifestPath)), LoadPublishManifest()); AssertPublishAssets( StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(intermediatePublishManifestPath)), publishPath, intermediateOutputPath); }
public void JSModules_ManifestIncludesModuleTargetPaths() { // Arrange var testAsset = "BlazorHosted"; ProjectDirectory = CreateAspNetSdkTestAsset(testAsset); File.WriteAllText(Path.Combine(ProjectDirectory.TestRoot, "blazorwasm", "wwwroot", "blazorwasm.lib.module.js"), "console.log('Hello initializer')"); File.WriteAllText(Path.Combine(ProjectDirectory.TestRoot, "razorclasslibrary", "wwwroot", "razorclasslibrary.lib.module.js"), "console.log('Hello RCL initializer')"); var build = new BuildCommand(ProjectDirectory, "blazorhosted"); build.WithWorkingDirectory(ProjectDirectory.TestRoot); var buildResult = build.Execute("/bl"); buildResult.Should().Pass(); var outputPath = build.GetOutputDirectory(DefaultTfm).ToString(); var intermediateOutputPath = build.GetIntermediateDirectory(DefaultTfm, "Debug").ToString(); var path = Path.Combine(intermediateOutputPath, "staticwebassets.build.json"); new FileInfo(path).Should().Exist(); var manifest = StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(path)); AssertManifest(manifest, LoadBuildManifest()); var blazorBootJson = new FileInfo(Path.Combine(intermediateOutputPath.Replace("blazorhosted", "blazorwasm"), "blazor.boot.json")); blazorBootJson.Should().Exist(); var contents = JsonSerializer.Deserialize <JsonDocument>(blazorBootJson.OpenRead()); contents.RootElement.TryGetProperty("resources", out var resources).Should().BeTrue(); resources.TryGetProperty("libraryInitializers", out var initializers).Should().BeTrue(); initializers.TryGetProperty("blazorwasm.lib.module.js", out _).Should().BeTrue(); initializers.TryGetProperty("_content/RazorClassLibrary/razorclasslibrary.lib.module.js", out var hash).Should().BeTrue(); // Do some validation to ensure the hash is included Convert.TryFromBase64String(hash.GetString().Substring("SHA256-".Length), new byte[256], out _).Should().BeTrue(); new FileInfo(Path.Combine(outputPath, "wwwroot", "blazorhosted.modules.json")).Should().NotExist(); }
public void Clean_RemovesManifestFrom_BuildAndIntermediateOutput() { var expectedManifest = LoadBuildManifest(); var testAsset = "RazorComponentApp"; ProjectDirectory = CreateAspNetSdkTestAsset(testAsset); var build = new BuildCommand(ProjectDirectory); build.Execute().Should().Pass(); var intermediateOutputPath = build.GetIntermediateDirectory(DefaultTfm, "Debug").ToString(); var outputPath = build.GetOutputDirectory(DefaultTfm, "Debug").ToString(); // GenerateStaticWebAssetsManifest should generate the manifest file. var path = Path.Combine(intermediateOutputPath, "StaticWebAssets.build.json"); new FileInfo(path).Should().Exist(); var manifest = StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(path)); AssertManifest(manifest, expectedManifest); // GenerateStaticWebAssetsManifest should copy the file to the output folder. var finalPath = Path.Combine(outputPath, "ComponentApp.staticwebassets.json"); new FileInfo(finalPath).Should().Exist(); var finalManifest = StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(finalPath)); AssertManifest(finalManifest, expectedManifest); var clean = new CleanCommand(Log, ProjectDirectory.Path); clean.Execute().Should().Pass(); // Obj folder manifest does not exist new FileInfo(path).Should().NotExist(); // Bin folder manifest does not exist new FileInfo(finalPath).Should().NotExist(); }
public void Publish_PublishSingleFile_GeneratesPublishJsonManifestAndCopiesPublishAssets() { var expectedManifest = LoadBuildManifest(); var testAsset = "RazorComponentApp"; ProjectDirectory = CreateAspNetSdkTestAsset(testAsset); var publish = new PublishCommand(ProjectDirectory); publish.Execute($"/p:PublishSingleFile=true /p:RuntimeIdentifier={RuntimeInformation.RuntimeIdentifier}").Should().Pass(); var intermediateOutputPath = publish.GetIntermediateDirectory(DefaultTfm, "Debug").ToString(); var publishPath = publish.GetOutputDirectory(DefaultTfm, "Debug").ToString(); // GenerateStaticWebAssetsManifest should generate the build manifest file. var path = Path.Combine(intermediateOutputPath, "StaticWebAssets.build.json"); new FileInfo(path).Should().Exist(); var manifest = StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(path)); AssertManifest(manifest, expectedManifest); // GenerateStaticWebAssetsManifest should not copy the file to the output folder. var finalPath = Path.Combine(publishPath, "ComponentApp.staticwebassets.json"); new FileInfo(finalPath).Should().NotExist(); // GenerateStaticWebAssetsManifest should generate the publish manifest file. var intermediatePublishManifestPath = Path.Combine(intermediateOutputPath, "StaticWebAssets.publish.json"); new FileInfo(path).Should().Exist(); AssertManifest( StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(intermediatePublishManifestPath)), LoadPublishManifest()); AssertPublishAssets( StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(intermediatePublishManifestPath)), publishPath, intermediateOutputPath); }
public void Build_DeployOnPublish_GeneratesPublishJsonManifestAndCopiesPublishAssets() { var expectedManifest = LoadBuildManifest(); var testAsset = "RazorComponentApp"; ProjectDirectory = CreateAspNetSdkTestAsset(testAsset); var build = new BuildCommand(ProjectDirectory); build.Execute("/p:DeployOnBuild=true").Should().Pass(); var intermediateOutputPath = build.GetIntermediateDirectory(DefaultTfm, "Debug").ToString(); var outputPath = build.GetOutputDirectory(DefaultTfm, "Debug").ToString(); // GenerateStaticWebAssetsManifest should generate the build manifest file. var path = Path.Combine(intermediateOutputPath, "StaticWebAssets.build.json"); new FileInfo(path).Should().Exist(); var manifest = StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(path)); AssertManifest(manifest, expectedManifest); // GenerateStaticWebAssetsManifest should copy the file to the output folder. var finalPath = Path.Combine(outputPath, "ComponentApp.staticwebassets.json"); new FileInfo(finalPath).Should().Exist(); var finalManifest = StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(finalPath)); AssertManifest(finalManifest, expectedManifest); // GenerateStaticWebAssetsManifest should generate the publish manifest file. var intermediatePublishManifestPath = Path.Combine(intermediateOutputPath, "StaticWebAssets.publish.json"); new FileInfo(path).Should().Exist(); var publishManifest = StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(intermediatePublishManifestPath)); AssertManifest(publishManifest, LoadPublishManifest()); }
public void BuildProjectWithReferences_IncorporatesInitializersFromClassLibraries() { var testAsset = "RazorAppWithPackageAndP2PReference"; ProjectDirectory = CreateAspNetSdkTestAsset(testAsset); var restore = new RestoreCommand(Log, Path.Combine(ProjectDirectory.TestRoot, "AppWithPackageAndP2PReference")); restore.Execute().Should().Pass(); CreateFile("console.log('Hello world AnotherClassLib')", "AnotherClassLib", "wwwroot", "AnotherClassLib.lib.module.js"); CreateFile("console.log('Hello world ClassLibrary')", "ClassLibrary", "wwwroot", "ClassLibrary.lib.module.js"); var build = new BuildCommand(Log, Path.Combine(ProjectDirectory.TestRoot, "AppWithPackageAndP2PReference")); build.WithWorkingDirectory(ProjectDirectory.Path); build.Execute("/bl").Should().Pass(); var intermediateOutputPath = build.GetIntermediateDirectory(DefaultTfm, "Debug").ToString(); var outputPath = build.GetOutputDirectory(DefaultTfm, "Debug").ToString(); var finalPath = Path.Combine(intermediateOutputPath, "staticwebassets.build.json"); AssertManifest( StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(finalPath)), LoadBuildManifest()); AssertBuildAssets( StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(finalPath)), outputPath, intermediateOutputPath); var file = new FileInfo(Path.Combine(intermediateOutputPath, "jsmodules", "jsmodules.build.manifest.json")); file.Should().Exist(); file.Should().Contain("_content/AnotherClassLib/AnotherClassLib.lib.module.js"); file.Should().Contain("_content/ClassLibrary/ClassLibrary.lib.module.js"); }
public void Build_DiscoversJsModulesBasedOnPatterns() { var testAsset = "RazorComponentApp"; ProjectDirectory = CreateAspNetSdkTestAsset(testAsset); // Components CreateFile("", ProjectDirectory.TestRoot, "Components", "Pages", "Counter.razor.js"); // MVC | Razor pages CreateFile("", ProjectDirectory.TestRoot, "Pages", "Index.cshtml"); CreateFile("", ProjectDirectory.TestRoot, "Pages", "Index.cshtml.js"); var build = new BuildCommand(ProjectDirectory); build.WithWorkingDirectory(ProjectDirectory.TestRoot); build.Execute("/bl").Should().Pass(); var intermediateOutputPath = build.GetIntermediateDirectory(DefaultTfm, "Debug").ToString(); var outputPath = build.GetOutputDirectory(DefaultTfm, "Debug").ToString(); var finalPath = Path.Combine(intermediateOutputPath, "staticwebassets.build.json"); var buildManifest = StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(finalPath)); AssertManifest( buildManifest, LoadBuildManifest()); buildManifest.Should().NotBeNull(); buildManifest.DiscoveryPatterns.Should().BeEmpty(); AssertBuildAssets( StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(finalPath)), outputPath, intermediateOutputPath); }
public void StaticWebAssets_BackCompatibilityPublish_Hosted_Works() { // Arrange var testAppName = "BlazorHosted"; ProjectDirectory = CreateAspNetSdkTestAsset(testAppName); ProjectDirectory.WithProjectChanges((project, document) => { if (Path.GetFileNameWithoutExtension(project) == "blazorwasm") { document.Descendants("TargetFramework").Single().ReplaceNodes("net5"); } if (Path.GetFileNameWithoutExtension(project) == "RazorClassLibrary") { document.Descendants("TargetFramework").Single().ReplaceNodes("netstandard2.1"); document.Descendants("PropertyGroup").First().Add(new XElement("RazorLangVersion", "3.0")); } if (Path.GetFileNameWithoutExtension(project) == "classlibrarywithsatelliteassemblies") { document.Descendants("TargetFramework").Single().ReplaceNodes("netstandard2.1"); document.Descendants("PropertyGroup").First().Add(new XElement("RazorLangVersion", "3.0")); } }); // Check that static web assets is correctly configured by setting up a css file to triger css isolation. // The list of publish files should not include bundle.scp.css and should include blazorwasm.styles.css File.WriteAllText(Path.Combine(ProjectDirectory.TestRoot, "blazorwasm", "App.razor.css"), "h1 { font-size: 16px; }"); var publish = new PublishCommand(ProjectDirectory, "blazorhosted"); publish.WithWorkingDirectory(ProjectDirectory.TestRoot); var publishResult = publish.Execute("/bl"); publishResult.Should().Pass(); var publishPath = publish.GetOutputDirectory(DefaultTfm).ToString(); var intermediateOutputPath = publish.GetIntermediateDirectory(DefaultTfm, "Debug").ToString(); // GenerateStaticWebAssetsManifest should generate the manifest file. var path = Path.Combine(intermediateOutputPath, "staticwebassets.publish.json"); new FileInfo(path).Should().Exist(); var manifest = StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(path)); // We have to special case this test given we are forcing `blazorwasm` to be a `net5` project above. // Given this, the `dotnet.*.js` file produced will be a dotnet.5.*.*.js file in line with the TFM and not the SDK (which is .NET 6 or beyond). // This conflicts with our assumptions throughout the rest of the test suite that the SDK version matches the TFM. // To minimize special casing throughout the entire test suite, we just update this particular test's assets to reflect the SDK version. var numFilesUpdated = 0; var frameworkFolder = Path.Combine(publishPath, "wwwroot", "_framework"); var frameworkFolderFiles = Directory.GetFiles(frameworkFolder, "*", new EnumerationOptions { RecurseSubdirectories = false }); foreach (var f in frameworkFolderFiles) { if (Regex.Match(f, DotNet5JSRegexPattern).Success) { File.Move(f, Regex.Replace(f, DotNet5JSRegexPattern, DotNet5JSTemplate)); numFilesUpdated++; } } Assert.Equal(3, numFilesUpdated); AssertManifest(manifest, LoadPublishManifest()); AssertPublishAssets( StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(path)), publishPath, intermediateOutputPath); }
public void StaticWebAssets_HostedApp_ReferencingNetStandardLibrary_Works() { // Arrange var testAppName = "BlazorHosted"; ProjectDirectory = CreateAspNetSdkTestAsset(testAppName); ProjectDirectory.WithProjectChanges((project, document) => { if (Path.GetFileNameWithoutExtension(project) == "blazorwasm") { document.Descendants("TargetFramework").Single().ReplaceNodes("net5"); } if (Path.GetFileNameWithoutExtension(project) == "RazorClassLibrary") { document.Descendants("TargetFramework").Single().ReplaceNodes("netstandard2.1"); document.Descendants("PropertyGroup").First().Add(new XElement("RazorLangVersion", "3.0")); } if (Path.GetFileNameWithoutExtension(project) == "classlibrarywithsatelliteassemblies") { document.Descendants("TargetFramework").Single().ReplaceNodes("netstandard2.1"); document.Descendants("PropertyGroup").First().Add(new XElement("RazorLangVersion", "3.0")); } }); var build = new BuildCommand(ProjectDirectory, "blazorhosted"); build.WithWorkingDirectory(ProjectDirectory.TestRoot); var buildResult = build.Execute("/bl"); buildResult.Should().Pass(); var outputPath = build.GetOutputDirectory(DefaultTfm).ToString(); var intermediateOutputPath = build.GetIntermediateDirectory(DefaultTfm, "Debug").ToString(); // GenerateStaticWebAssetsManifest should generate the manifest file. var path = Path.Combine(intermediateOutputPath, "staticwebassets.build.json"); new FileInfo(path).Should().Exist(); var manifest = StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(path)); // We have to special case this test given we are forcing `blazorwasm` to be a `net5` project above. // Given this, the `dotnet.*.js` file produced will be a dotnet.5.*.*.js file in line with the TFM and not the SDK (which is .NET 6 or beyond). // This conflicts with our assumptions throughout the rest of the test suite that the SDK version matches the TFM. // To minimize special casing throughout the entire test suite, we just update this particular test's assets to reflect the SDK version. var numFilesUpdated = 0; foreach (var f in manifest.Assets) { if (Regex.Match(f.RelativePath, DotNet5JSRegexPattern).Success) { f.Identity = Regex.Replace(f.Identity, DotNet5JSRegexPattern, DotNet5JSTemplate); f.RelativePath = Regex.Replace(f.RelativePath, DotNet5JSRegexPattern, DotNet5JSTemplate); f.OriginalItemSpec = Regex.Replace(f.OriginalItemSpec, DotNet5JSRegexPattern, DotNet5JSTemplate); numFilesUpdated++; } } Assert.Equal(2, numFilesUpdated); AssertManifest(manifest, LoadBuildManifest()); // GenerateStaticWebAssetsManifest should copy the file to the output folder. var finalPath = Path.Combine(outputPath, "blazorhosted.staticwebassets.runtime.json"); new FileInfo(finalPath).Should().Exist(); AssertBuildAssets( StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(path)), outputPath, intermediateOutputPath); }
public void PublishProjectWithReferences_NoBuild_GeneratesPublishJsonManifestAndCopiesPublishAssets() { var testAsset = "RazorAppWithPackageAndP2PReference"; ProjectDirectory = CreateAspNetSdkTestAsset(testAsset); var build = new BuildCommand(ProjectDirectory, "AppWithPackageAndP2PReference"); build.WithWorkingDirectory(ProjectDirectory.TestRoot); build.Execute("/bl").Should().Pass(); var intermediateOutputPath = build.GetIntermediateDirectory(DefaultTfm, "Debug").ToString(); var outputPath = build.GetOutputDirectory(DefaultTfm, "Debug").ToString(); // GenerateStaticWebAssetsManifest should generate the manifest file. var path = Path.Combine(intermediateOutputPath, "StaticWebAssets.build.json"); var objManifestFile = new FileInfo(path); objManifestFile.Should().Exist(); var objManifestFileTimeStamp = objManifestFile.LastWriteTimeUtc; AssertManifest( StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(path)), LoadBuildManifest()); // GenerateStaticWebAssetsManifest should copy the file to the output folder. var finalPath = Path.Combine(outputPath, "AppWithPackageAndP2PReference.staticwebassets.json"); var binManifestFile = new FileInfo(finalPath); binManifestFile.Should().Exist(); var binManifestTimeStamp = binManifestFile.LastWriteTimeUtc; var manifest = File.ReadAllText(finalPath); AssertManifest( StaticWebAssetsManifest.FromJsonString(manifest), LoadBuildManifest()); // Publish no build var publish = new PublishCommand(Log, Path.Combine(ProjectDirectory.TestRoot, "AppWithPackageAndP2PReference")); var publishResult = publish.Execute("/p:NoBuild=true", "/p:ErrorOnDuplicatePublishOutputFiles=false"); var publishPath = build.GetOutputDirectory(DefaultTfm, "Debug").ToString(); publishResult.Should().Pass(); new FileInfo(path).LastWriteTimeUtc.Should().Be(objManifestFileTimeStamp); var seconbObjManifest = StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(path)); AssertManifest(seconbObjManifest, LoadBuildManifest()); // GenerateStaticWebAssetsManifest should copy the file to the output folder. var seconBinManifestPath = Path.Combine(outputPath, "AppWithPackageAndP2PReference.staticwebassets.json"); var secondBinManifestFile = new FileInfo(seconBinManifestPath); secondBinManifestFile.Should().Exist(); secondBinManifestFile.LastWriteTimeUtc.Should().Be(binManifestTimeStamp); var secondBinManifest = StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(seconBinManifestPath)); AssertManifest(secondBinManifest, LoadBuildManifest()); // GenerateStaticWebAssetsManifest should generate the publish manifest file. var intermediatePublishManifestPath = Path.Combine(intermediateOutputPath, "StaticWebAssets.publish.json"); new FileInfo(path).Should().Exist(); var publishManifest = StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(intermediatePublishManifestPath)); AssertManifest(publishManifest, LoadPublishManifest()); AssertPublishAssets( StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(intermediatePublishManifestPath)), publishPath, intermediateOutputPath); }
public void Publish_NoBuild_GeneratesPublishJsonManifestAndCopiesPublishAssets() { var expectedManifest = LoadBuildManifest(); var testAsset = "RazorComponentApp"; ProjectDirectory = CreateAspNetSdkTestAsset(testAsset); var build = new BuildCommand(ProjectDirectory); build.Execute().Should().Pass(); var intermediateOutputPath = build.GetIntermediateDirectory(DefaultTfm, "Debug").ToString(); var publishPath = build.GetOutputDirectory(DefaultTfm, "Debug").ToString(); // GenerateStaticWebAssetsManifest should generate the manifest file. var path = Path.Combine(intermediateOutputPath, "StaticWebAssets.build.json"); var objManifestFile = new FileInfo(path); objManifestFile.Should().Exist(); var objManifestFileTimeStamp = objManifestFile.LastWriteTimeUtc; var manifest = StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(path)); AssertManifest(manifest, expectedManifest); // GenerateStaticWebAssetsManifest should copy the file to the output folder. var finalPath = Path.Combine(publishPath, "ComponentApp.staticwebassets.json"); var binManifestFile = new FileInfo(finalPath); binManifestFile.Should().Exist(); var binManifestTimeStamp = binManifestFile.LastWriteTimeUtc; var finalManifest = StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(finalPath)); AssertManifest(finalManifest, expectedManifest); // Publish no build var publish = new PublishCommand(ProjectDirectory); publish.Execute("/p:NoBuild=true").Should().Pass(); var secondObjTimeStamp = new FileInfo(path).LastWriteTimeUtc; secondObjTimeStamp.Should().Be(objManifestFileTimeStamp); var seconbObjManifest = StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(path)); AssertManifest(seconbObjManifest, expectedManifest); // GenerateStaticWebAssetsManifest should copy the file to the output folder. var seconBinManifestPath = Path.Combine(publishPath, "ComponentApp.staticwebassets.json"); var secondBinManifestFile = new FileInfo(seconBinManifestPath); secondBinManifestFile.Should().Exist(); secondBinManifestFile.LastWriteTimeUtc.Should().Be(binManifestTimeStamp); var secondBinManifest = StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(seconBinManifestPath)); AssertManifest(secondBinManifest, expectedManifest); // GenerateStaticWebAssetsManifest should generate the publish manifest file. var intermediatePublishManifestPath = Path.Combine(intermediateOutputPath, "StaticWebAssets.publish.json"); new FileInfo(path).Should().Exist(); AssertManifest( StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(intermediatePublishManifestPath)), LoadPublishManifest()); AssertPublishAssets( StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(intermediatePublishManifestPath)), publishPath, intermediateOutputPath); }
public void Rebuild_RegeneratesJsonManifestAndCopiesItToOutputFolder() { var testAsset = "RazorComponentApp"; ProjectDirectory = CreateAspNetSdkTestAsset(testAsset); var build = new BuildCommand(ProjectDirectory); build.Execute().Should().Pass(); var intermediateOutputPath = build.GetIntermediateDirectory(DefaultTfm, "Debug").ToString(); var outputPath = build.GetOutputDirectory(DefaultTfm, "Debug").ToString(); // GenerateStaticWebAssetsManifest should generate the manifest file. var path = Path.Combine(intermediateOutputPath, "StaticWebAssets.build.json"); var originalObjFile = new FileInfo(path); originalObjFile.Should().Exist(); var objManifestContents = File.ReadAllText(path); AssertManifest(StaticWebAssetsManifest.FromJsonString(objManifestContents), LoadBuildManifest()); // GenerateStaticWebAssetsManifest should copy the file to the output folder. var finalPath = Path.Combine(outputPath, "ComponentApp.staticwebassets.json"); var originalFile = new FileInfo(finalPath); originalFile.Should().Exist(); var binManifestContents = File.ReadAllText(finalPath); binManifestContents.Should().Be(objManifestContents); // rebuild build var rebuild = new RebuildCommand(Log, ProjectDirectory.Path); rebuild.Execute().Should().Pass(); var secondPath = Path.Combine(intermediateOutputPath, "StaticWebAssets.build.json"); var secondObjFile = new FileInfo(secondPath); secondObjFile.Should().Exist(); var secondObjManifest = File.ReadAllText(secondPath); AssertManifest( StaticWebAssetsManifest.FromJsonString(secondObjManifest), LoadBuildManifest("Rebuild"), "Rebuild"); secondObjManifest.Should().Be(objManifestContents); // GenerateStaticWebAssetsManifest should copy the file to the output folder. var secondFinalPath = Path.Combine(outputPath, "ComponentApp.staticwebassets.json"); var secondFinalFile = new FileInfo(secondFinalPath); secondFinalFile.Should().Exist(); var secondBinManifest = File.ReadAllText(secondFinalPath); secondBinManifest.Should().Be(binManifestContents); secondBinManifest.Should().Be(secondObjManifest); secondObjFile.LastWriteTimeUtc.Should().NotBe(originalObjFile.LastWriteTimeUtc); secondFinalFile.LastWriteTimeUtc.Should().NotBe(originalFile.LastWriteTimeUtc); AssertBuildAssets( StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(finalPath)), outputPath, intermediateOutputPath, "Rebuild"); }
public void PublishProjectWithReferences_DifferentBuildAndPublish_LibraryInitializers() { var testAsset = "RazorAppWithPackageAndP2PReference"; ProjectDirectory = CreateAspNetSdkTestAsset(testAsset); var restore = new RestoreCommand(Log, Path.Combine(ProjectDirectory.TestRoot, "AppWithPackageAndP2PReference")); restore.Execute().Should().Pass(); CreateFile("console.log('Hello world AnotherClassLib publish')", "AnotherClassLib", "wwwroot", "AnotherClassLib.lib.module.js"); CreateFile("console.log('Hello world AnotherClassLib')", "AnotherClassLib", "wwwroot", "AnotherClassLib.lib.module.build.js"); ProjectDirectory.WithProjectChanges((project, document) => { if (project.EndsWith("AnotherClassLib.csproj")) { document.Root.Add(new XElement("ItemGroup", new XElement("Content", new XAttribute("Update", "wwwroot\\AnotherClassLib.lib.module.build.js"), new XAttribute("CopyToPublishDirectory", "Never"), new XAttribute("TargetPath", "wwwroot\\AnotherClassLib.lib.module.js")))); } }); var publish = new PublishCommand(Log, Path.Combine(ProjectDirectory.TestRoot, "AppWithPackageAndP2PReference")); publish.WithWorkingDirectory(ProjectDirectory.Path); publish.Execute("/bl").Should().Pass(); var intermediateOutputPath = publish.GetIntermediateDirectory(DefaultTfm, "Debug").ToString(); var outputPath = publish.GetOutputDirectory(DefaultTfm, "Debug").ToString(); var path = Path.Combine(intermediateOutputPath, "staticwebassets.build.json");; var buildManifest = StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(path)); var initializers = buildManifest.Assets.Where(a => a.RelativePath == "AnotherClassLib.lib.module.js"); initializers.Should().HaveCount(1); initializers.Should().Contain(a => a.IsBuildOnly()); AssertManifest( buildManifest, LoadBuildManifest()); var finalPath = Path.Combine(intermediateOutputPath, "staticwebassets.publish.json"); AssertManifest( StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(finalPath)), LoadPublishManifest()); AssertBuildAssets( StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(finalPath)), outputPath, intermediateOutputPath); var modulesManifest = new FileInfo(Path.Combine(outputPath, "wwwroot", "AppWithPackageAndP2PReference.modules.json")); modulesManifest.Should().Exist(); modulesManifest.Should().Contain("_content/AnotherClassLib/AnotherClassLib.lib.module.js"); modulesManifest.Should().NotContain("_content/ClassLibrary/AnotherClassLib.lib.module.js"); var moduleFile = new FileInfo(Path.Combine(outputPath, "wwwroot", "_content", "AnotherClassLib", "AnotherClassLib.lib.module.js")); moduleFile.Should().Exist(); moduleFile.Should().Contain("console.log('Hello world AnotherClassLib publish')"); }
public void Build_SatelliteAssembliesAreCopiedToBuildOutput() { // Arrange var testAppName = "BlazorWasmWithLibrary"; ProjectDirectory = CreateAspNetSdkTestAsset(testAppName); ProjectDirectory.WithProjectChanges((path, project) => { if (path.Contains("blazorwasm")) { var ns = project.Root.Name.Namespace; var propertyGroup = new XElement(ns + "PropertyGroup"); propertyGroup.Add(new XElement("DefineConstants", @"$(DefineConstants);REFERENCE_classlibrarywithsatelliteassemblies")); var itemGroup = new XElement(ns + "ItemGroup"); itemGroup.Add(new XElement("ProjectReference", new XAttribute("Include", @"..\classlibrarywithsatelliteassemblies\classlibrarywithsatelliteassemblies.csproj"))); project.Root.Add(propertyGroup); project.Root.Add(itemGroup); } }); var resxfileInProject = Path.Combine(ProjectDirectory.TestRoot, "blazorwasm", "Resources.ja.resx.txt"); File.Move(resxfileInProject, Path.Combine(ProjectDirectory.TestRoot, "blazorwasm", "Resource.ja.resx")); var buildCommand = new BuildCommand(ProjectDirectory, "blazorwasm"); buildCommand.WithWorkingDirectory(ProjectDirectory.TestRoot); buildCommand.Execute("/bl").Should().Pass(); var outputPath = buildCommand.GetOutputDirectory(DefaultTfm).ToString(); var intermediateOutputPath = buildCommand.GetIntermediateDirectory(DefaultTfm).ToString(); // GenerateStaticWebAssetsManifest should generate the manifest file. var path = Path.Combine(intermediateOutputPath, "staticwebassets.build.json"); new FileInfo(path).Should().Exist(); var manifest = StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(path)); AssertManifest(manifest, LoadBuildManifest()); // GenerateStaticWebAssetsManifest should copy the file to the output folder. var finalPath = Path.Combine(outputPath, "blazorwasm.staticwebassets.runtime.json"); new FileInfo(finalPath).Should().Exist(); AssertBuildAssets( StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(path)), outputPath, intermediateOutputPath); new FileInfo(Path.Combine(outputPath, "wwwroot", "_framework", "blazorwasm.dll")).Should().Exist(); new FileInfo(Path.Combine(outputPath, "wwwroot", "_framework", "classlibrarywithsatelliteassemblies.dll")).Should().Exist(); new FileInfo(Path.Combine(outputPath, "wwwroot", "_framework", "Microsoft.CodeAnalysis.CSharp.dll")).Should().Exist(); new FileInfo(Path.Combine(outputPath, "wwwroot", "_framework", "fr", "Microsoft.CodeAnalysis.CSharp.resources.dll")).Should().Exist(); var bootJsonPath = new FileInfo(Path.Combine(outputPath, "wwwroot", "_framework", "blazor.boot.json")); bootJsonPath.Should().Contain("\"Microsoft.CodeAnalysis.CSharp.dll\""); bootJsonPath.Should().Contain("\"fr\\/Microsoft.CodeAnalysis.CSharp.resources.dll\""); }