diff --git a/Blazor.sln b/Blazor.sln index 157be7621b..916d1d76c1 100644 --- a/Blazor.sln +++ b/Blazor.sln @@ -93,6 +93,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "benchmarks", "benchmarks", EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Blazor.Performance", "benchmarks\Microsoft.AspNetCore.Blazor.Performance\Microsoft.AspNetCore.Blazor.Performance.csproj", "{50F6820F-D058-4E68-9E15-801F893F514E}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlazorContent.CSharp", "src\Microsoft.AspNetCore.Blazor.Templates\content\BlazorContent.CSharp\BlazorContent.CSharp.csproj", "{3A457B14-D91B-4FFF-A81A-8F350BDB911F}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -324,6 +326,10 @@ Global {50F6820F-D058-4E68-9E15-801F893F514E}.Release|Any CPU.Build.0 = Release|Any CPU {50F6820F-D058-4E68-9E15-801F893F514E}.ReleaseNoVSIX|Any CPU.ActiveCfg = Release|Any CPU {50F6820F-D058-4E68-9E15-801F893F514E}.ReleaseNoVSIX|Any CPU.Build.0 = Release|Any CPU + {3A457B14-D91B-4FFF-A81A-8F350BDB911F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3A457B14-D91B-4FFF-A81A-8F350BDB911F}.DebugNoVSIX|Any CPU.ActiveCfg = Debug|Any CPU + {3A457B14-D91B-4FFF-A81A-8F350BDB911F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3A457B14-D91B-4FFF-A81A-8F350BDB911F}.ReleaseNoVSIX|Any CPU.ActiveCfg = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -365,6 +371,7 @@ Global {9088E4E4-B855-457F-AE9E-D86709A5E1F4} = {F563ABB6-85FB-4CFC-B0D2-1D5130E8246D} {C57382BC-EE93-49D5-BC40-5C98AF8AA048} = {4AE0D35B-D97A-44D0-8392-C9240377DCCE} {50F6820F-D058-4E68-9E15-801F893F514E} = {36A7DEB7-5F88-4BFB-B57E-79EEC9950E25} + {3A457B14-D91B-4FFF-A81A-8F350BDB911F} = {E8EBA72C-D555-43AE-BC98-F0B2D05F6A07} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {504DA352-6788-4DC0-8705-82167E72A4D3} diff --git a/src/Microsoft.AspNetCore.Blazor.Build/Cli/Commands/BuildIndexHtmlCommand.cs b/src/Microsoft.AspNetCore.Blazor.Build/Cli/Commands/BuildIndexHtmlCommand.cs index 5f160d64f9..189a359b3c 100644 --- a/src/Microsoft.AspNetCore.Blazor.Build/Cli/Commands/BuildIndexHtmlCommand.cs +++ b/src/Microsoft.AspNetCore.Blazor.Build/Cli/Commands/BuildIndexHtmlCommand.cs @@ -15,15 +15,11 @@ namespace Microsoft.AspNetCore.Blazor.Build.Cli.Commands CommandOptionType.SingleValue); var references = command.Option("--reference", - "The path from the _bin folder to a given referenced dll file (Typically just the dll name)", + "The path from the _bin folder to a given referenced dll file (typically just the dll name)", CommandOptionType.MultipleValue); - var jsReferences = command.Option("--js", - "Adds a "); // Set a flag so we know not to emit anything else until the special diff --git a/src/Microsoft.AspNetCore.Blazor.Build/targets/Blazor.MonoRuntime.targets b/src/Microsoft.AspNetCore.Blazor.Build/targets/Blazor.MonoRuntime.targets index 1be7c0a433..aa88f41f09 100644 --- a/src/Microsoft.AspNetCore.Blazor.Build/targets/Blazor.MonoRuntime.targets +++ b/src/Microsoft.AspNetCore.Blazor.Build/targets/Blazor.MonoRuntime.targets @@ -227,8 +227,11 @@ + + $(BlazorIntermediateOutputPath) + - $(BlazorIntermediateOutputPath)$(BlazorOutputIndexHtmlName) + $(BlazorIndexHtmlOutputDir)$(BlazorOutputIndexHtmlName) $(BlazorIntermediateOutputPath)inputs.index.cache @@ -568,8 +571,6 @@ - - @@ -588,26 +589,30 @@ + <_UnlinkedAppReferencesPaths Include="@(_BlazorDependencyInput)" /> <_AppReferences Include="@(BlazorItemOutput->WithMetadataValue('Type','Assembly')->WithMetadataValue('PrimaryOutput','')->'%(FileName)%(Extension)')" /> - <_JsReferences Include="@(BlazorPackageJsRef->'_content/%(SourcePackage)/%(RecursiveDir)%(FileName)%(Extension)')" /> - <_CssReferences Include="@(BlazorPackageCssRef->'_content/%(SourcePackage)/%(RecursiveDir)%(FileName)%(Extension)')" /> <_LinkerEnabledFlag Condition="'$(_BlazorShouldLinkApplicationAssemblies)' != ''">--linker-enabled - + <_BlazorIndex Include="$(BlazorIndexHtmlOutputPath)" /> + <_BlazorIndexEmbeddedContentFile Include="$(BlazorIndexHtmlOutputDir)_content\**\*.*" /> $(ProjectDir)$(OutputPath)dist/%(FileName)%(Extension) EntryPoint + + $(ProjectDir)$(OutputPath)dist/_content/%(RecursiveDir)%(FileName)%(Extension) + + diff --git a/src/Microsoft.AspNetCore.Blazor.Templates/content/BlazorContent.CSharp/.template.config/dotnetcli.host.json b/src/Microsoft.AspNetCore.Blazor.Templates/content/BlazorContent.CSharp/.template.config/dotnetcli.host.json new file mode 100644 index 0000000000..11797289ab --- /dev/null +++ b/src/Microsoft.AspNetCore.Blazor.Templates/content/BlazorContent.CSharp/.template.config/dotnetcli.host.json @@ -0,0 +1,12 @@ +{ + "$schema": "http://json.schemastore.org/dotnetcli.host", + "symbolInfo": { + "skipRestore": { + "longName": "no-restore", + "shortName": "" + }, + "Framework": { + "longName": "framework" + } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Blazor.Templates/content/BlazorContent.CSharp/.template.config/icon.png b/src/Microsoft.AspNetCore.Blazor.Templates/content/BlazorContent.CSharp/.template.config/icon.png new file mode 100644 index 0000000000..572a095fa0 Binary files /dev/null and b/src/Microsoft.AspNetCore.Blazor.Templates/content/BlazorContent.CSharp/.template.config/icon.png differ diff --git a/src/Microsoft.AspNetCore.Blazor.Templates/content/BlazorContent.CSharp/.template.config/template.json b/src/Microsoft.AspNetCore.Blazor.Templates/content/BlazorContent.CSharp/.template.config/template.json new file mode 100644 index 0000000000..45e3bf57b7 --- /dev/null +++ b/src/Microsoft.AspNetCore.Blazor.Templates/content/BlazorContent.CSharp/.template.config/template.json @@ -0,0 +1,70 @@ +{ + "author": "Microsoft", + "classifications": [ + "Web", + "Blazor", + "Content" + ], + "groupIdentity": "Microsoft.Web.Blazor.Content", + "identity": "Microsoft.Web.Blazor.Content.CSharp", + "name": "Blazor (content)", + "preferNameDirectory": true, + "primaryOutputs": [ + { + "path": "BlazorContent.CSharp.csproj" + } + ], + "shortName": "blazorcontent", + "sourceName": "BlazorContent.CSharp", + "sources": [ + { + "source": "./", + "target": "./", + "exclude": [ + ".template.config/**" + ] + } + ], + "symbols": { + "Framework": { + "type": "parameter", + "description": "The target framework for the project.", + "datatype": "choice", + "choices": [ + { + "choice": "netcoreapp2.0", + "description": "Target netcoreapp2.0" + } + ], + "replaces": "netcoreapp2.0", + "defaultValue": "netcoreapp2.0" + }, + "HostIdentifier": { + "type": "bind", + "binding": "HostIdentifier" + }, + "skipRestore": { + "type": "parameter", + "datatype": "bool", + "description": "If specified, skips the automatic restore of the project on create.", + "defaultValue": "false" + } + }, + "tags": { + "language": "C#", + "type": "project" + }, + "postActions": [ + { + "condition": "(!skipRestore)", + "description": "Restore NuGet packages required by this project.", + "manualInstructions": [ + { + "text": "Run 'dotnet restore'" + } + ], + "actionId": "210D431B-A78B-4D2F-B762-4ED3E3EA9025", + "continueOnError": true + } + ] +} diff --git a/src/Microsoft.AspNetCore.Blazor.Templates/content/BlazorContent.CSharp/BlazorContent.CSharp.csproj b/src/Microsoft.AspNetCore.Blazor.Templates/content/BlazorContent.CSharp/BlazorContent.CSharp.csproj new file mode 100644 index 0000000000..6471993770 --- /dev/null +++ b/src/Microsoft.AspNetCore.Blazor.Templates/content/BlazorContent.CSharp/BlazorContent.CSharp.csproj @@ -0,0 +1,26 @@ + + + + netstandard2.0 + library + true + false + + + https://dotnet.myget.org/F/blazor-dev/api/v3/index.json;$(RestoreSources) + + + + + + + + + + + + + + + + diff --git a/src/Microsoft.AspNetCore.Blazor.Templates/content/BlazorContent.CSharp/Component1.cshtml b/src/Microsoft.AspNetCore.Blazor.Templates/content/BlazorContent.CSharp/Component1.cshtml new file mode 100644 index 0000000000..e8cb655c24 --- /dev/null +++ b/src/Microsoft.AspNetCore.Blazor.Templates/content/BlazorContent.CSharp/Component1.cshtml @@ -0,0 +1,3 @@ +
+ This Blazor component is defined in the BlazorContent.CSharp package. +
diff --git a/src/Microsoft.AspNetCore.Blazor.Templates/content/BlazorContent.CSharp/ExampleJsInterop.cs b/src/Microsoft.AspNetCore.Blazor.Templates/content/BlazorContent.CSharp/ExampleJsInterop.cs new file mode 100644 index 0000000000..f51e06453a --- /dev/null +++ b/src/Microsoft.AspNetCore.Blazor.Templates/content/BlazorContent.CSharp/ExampleJsInterop.cs @@ -0,0 +1,15 @@ +using System; +using Microsoft.AspNetCore.Blazor.Browser.Interop; + +namespace BlazorContent.CSharp +{ + public class ExampleJsInterop + { + public static string Prompt(string message) + { + return RegisteredFunction.Invoke( + "BlazorContent.CSharp.ExampleJsInterop.Prompt", + message); + } + } +} diff --git a/src/Microsoft.AspNetCore.Blazor.Templates/content/BlazorContent.CSharp/content/background.png b/src/Microsoft.AspNetCore.Blazor.Templates/content/BlazorContent.CSharp/content/background.png new file mode 100644 index 0000000000..e15a3bde6e Binary files /dev/null and b/src/Microsoft.AspNetCore.Blazor.Templates/content/BlazorContent.CSharp/content/background.png differ diff --git a/src/Microsoft.AspNetCore.Blazor.Templates/content/BlazorContent.CSharp/content/exampleJsInterop.js b/src/Microsoft.AspNetCore.Blazor.Templates/content/BlazorContent.CSharp/content/exampleJsInterop.js new file mode 100644 index 0000000000..2398cacd8d --- /dev/null +++ b/src/Microsoft.AspNetCore.Blazor.Templates/content/BlazorContent.CSharp/content/exampleJsInterop.js @@ -0,0 +1,6 @@ +// This file is to show how a content package may provide JavaScript interop features +// wrapped in a .NET API + +Blazor.registerFunction('BlazorContent.CSharp.ExampleJsInterop.Prompt', function (message) { + return prompt(message, 'Type anything here'); +}); diff --git a/src/Microsoft.AspNetCore.Blazor.Templates/content/BlazorContent.CSharp/content/styles.css b/src/Microsoft.AspNetCore.Blazor.Templates/content/BlazorContent.CSharp/content/styles.css new file mode 100644 index 0000000000..d968f70925 --- /dev/null +++ b/src/Microsoft.AspNetCore.Blazor.Templates/content/BlazorContent.CSharp/content/styles.css @@ -0,0 +1,11 @@ +/* + This file is to show how CSS and other static resources (such as images) can be + used from a content project/package. +*/ + +.my-component { + border: 2px dashed red; + padding: 1em; + margin: 1em 0; + background-image: url('background.png'); +} diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/IndexHtmlWriterTest.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/IndexHtmlWriterTest.cs index 6b5bdae3a1..e3ad517e12 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/IndexHtmlWriterTest.cs +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/IndexHtmlWriterTest.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using AngleSharp.Parser.Html; +using System; using System.Linq; using Xunit; @@ -27,15 +28,12 @@ namespace Microsoft.AspNetCore.Blazor.Build.Test {htmlTemplateSuffix}"; var assemblyReferences = new string[] { "System.Abc.dll", "MyApp.ClassLib.dll", }; - var jsReferences = new string[] { "some/file.js", "another.js" }; - var cssReferences = new string[] { "my/styles.css" }; var instance = IndexHtmlWriter.GetIndexHtmlContents( htmlTemplate, "MyApp.Entrypoint", "MyNamespace.MyType::MyMethod", assemblyReferences, - jsReferences, - cssReferences, + Enumerable.Empty(), linkerEnabled: true); // Act & Assert: Start and end is not modified (including formatting) @@ -57,16 +55,6 @@ namespace Microsoft.AspNetCore.Blazor.Build.Test Assert.Equal(string.Empty, scriptElem.Attributes["custom1"].Value); Assert.Equal("value", scriptElem.Attributes["custom2"].Value); Assert.Equal("true", scriptElem.Attributes["linker-enabled"].Value); - - // Assert: Also contains script tags referencing JS files - Assert.Equal( - scriptElems.Skip(1).Select(tag => tag.GetAttribute("src")), - jsReferences); - - // Assert: Also contains link tags referencing CSS files - Assert.Equal( - linkElems.Select(tag => tag.GetAttribute("href")), - cssReferences); } [Fact] @@ -79,10 +67,50 @@ namespace Microsoft.AspNetCore.Blazor.Build.Test var cssReferences = new string[] { "my/styles.css" }; var content = IndexHtmlWriter.GetIndexHtmlContents( - htmlTemplate, "MyApp.Entrypoint", "MyNamespace.MyType::MyMethod", assemblyReferences, jsReferences, cssReferences, linkerEnabled: true); + htmlTemplate, "MyApp.Entrypoint", "MyNamespace.MyType::MyMethod", assemblyReferences, Enumerable.Empty(), linkerEnabled: true); // Assert Assert.Equal(htmlTemplate, content); } + + [Fact] + public void InjectsAdditionalTagsForEmbeddedContent() + { + // Arrange + var htmlTemplate = "Start End"; + var embeddedContent = new[] + { + new EmbeddedResourceInfo(EmbeddedResourceKind.Static, "my/static/file"), + new EmbeddedResourceInfo(EmbeddedResourceKind.Css, "css/first.css"), + new EmbeddedResourceInfo(EmbeddedResourceKind.JavaScript, "javascript/first.js"), + new EmbeddedResourceInfo(EmbeddedResourceKind.Css, "css/second.css"), + new EmbeddedResourceInfo(EmbeddedResourceKind.JavaScript, "javascript/second.js"), + }; + + // Act + var resultHtml = IndexHtmlWriter.GetIndexHtmlContents( + htmlTemplate, + "MyApp.Entrypoint", + "MyNamespace.MyType::MyMethod", + assemblyReferences: new[] { "Something.dll" }, + embeddedContent: embeddedContent, + linkerEnabled: true); + + // Assert + var parsedHtml = new HtmlParser().Parse(resultHtml); + var blazorBootScript = parsedHtml.GetElementById("testboot"); + Assert.NotNull(blazorBootScript); + Assert.Equal( + "Start " + + blazorBootScript.OuterHtml + // First we insert the CSS file tags in order + + Environment.NewLine + "" + + Environment.NewLine + "" + // Then the JS file tags in order, each with 'defer' + + Environment.NewLine + "" + + Environment.NewLine + "" + + " End", + resultHtml); + } } } diff --git a/test/testapps/BasicTestApp/BasicTestApp.csproj b/test/testapps/BasicTestApp/BasicTestApp.csproj index 3b8e844999..20dcbff895 100644 --- a/test/testapps/BasicTestApp/BasicTestApp.csproj +++ b/test/testapps/BasicTestApp/BasicTestApp.csproj @@ -13,11 +13,6 @@ - - - - - diff --git a/test/testapps/TestContentPackage/TestContentPackage.csproj b/test/testapps/TestContentPackage/TestContentPackage.csproj index bcfa81a9fb..d2f293ab15 100644 --- a/test/testapps/TestContentPackage/TestContentPackage.csproj +++ b/test/testapps/TestContentPackage/TestContentPackage.csproj @@ -7,9 +7,14 @@ - - - + + + + + + + + diff --git a/test/testapps/TestContentPackage/build/TestContentPackage.props b/test/testapps/TestContentPackage/build/TestContentPackage.props deleted file mode 100644 index fc24a60c2b..0000000000 --- a/test/testapps/TestContentPackage/build/TestContentPackage.props +++ /dev/null @@ -1,19 +0,0 @@ - - - - <_PackageId>TestContentPackage - <_ContentDir>$(MSBuildThisFileDirectory)..\content\ - - - - - - - - - - - - - -