When compiling Razor components, take base namespace from host project

This commit is contained in:
Steve Sanderson 2018-01-14 14:40:57 +00:00
parent a32b857d96
commit a03cb48c7a
2 changed files with 7 additions and 4 deletions

View File

@ -25,13 +25,16 @@ namespace Microsoft.Blazor.Build.Cli.Commands
var outputFilePath = command.Option("--output",
"The location where the resulting C# source file should be written",
CommandOptionType.SingleValue);
var baseNamespace = command.Option("--namespace",
"The base namespace for the generated C# classes.",
CommandOptionType.SingleValue);
var verboseFlag = command.Option("--verbose",
"Indicates that verbose console output should written",
CommandOptionType.NoValue);
command.OnExecute(() =>
{
if (!VerifyRequiredOptionsProvided(sourceDirPath, outputFilePath))
if (!VerifyRequiredOptionsProvided(sourceDirPath, outputFilePath, baseNamespace))
{
return 1;
}
@ -49,7 +52,7 @@ namespace Microsoft.Blazor.Build.Cli.Commands
var diagnostics = new RazorCompiler().CompileFiles(
sourceDirPathValue,
inputRazorFilePaths,
"Blazor", // TODO: Add required option for namespace
baseNamespace.Value(),
outputWriter,
verboseFlag.HasValue() ? Console.Out : null);

View File

@ -1,11 +1,11 @@
<Project>
<Target Name="BlazorCompileRazorComponents" BeforeTargets="CoreCompile">
<PropertyGroup>
<BlazorComponentsNamespace>BlazorComponents</BlazorComponentsNamespace>
<BlazorComponentsNamespace>$(RootNamespace)</BlazorComponentsNamespace>
<IsDesignTimeBuild Condition="'$(DesignTimeBuild)' == 'true' OR '$(BuildingProject)' != 'true'">true</IsDesignTimeBuild>
<GeneratedFilePath>$(IntermediateOutputPath)BlazorRazorComponents.g.cs</GeneratedFilePath>
</PropertyGroup>
<Exec Command="$(BlazorBuildExe) buildrazor --source $(ProjectDir) --output $(GeneratedFilePath)" />
<Exec Command="$(BlazorBuildExe) buildrazor --source $(ProjectDir) --namespace $(BlazorComponentsNamespace) --output $(GeneratedFilePath)" />
<ItemGroup>
<Compile Include="$(GeneratedFilePath)" />
</ItemGroup>