parent
bfdd939e26
commit
d81cce8a25
|
|
@ -3,8 +3,8 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Design.Internal;
|
using Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Design.Internal;
|
||||||
using Microsoft.DotNet.InternalAbstractions;
|
using Microsoft.DotNet.InternalAbstractions;
|
||||||
|
|
@ -94,7 +94,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Internal
|
||||||
dispatchArgs.Add(CommonOptions.EmbedViewSourceTemplate);
|
dispatchArgs.Add(CommonOptions.EmbedViewSourceTemplate);
|
||||||
}
|
}
|
||||||
|
|
||||||
var compilerOptions = runtimeContext.ProjectFile.GetCompilerOptions(TargetFramework, Configuration);
|
var compilerOptions = runtimeContext.ProjectFile.GetCompilerOptions(runtimeContext.TargetFramework, Configuration);
|
||||||
if (!string.IsNullOrEmpty(compilerOptions.KeyFile))
|
if (!string.IsNullOrEmpty(compilerOptions.KeyFile))
|
||||||
{
|
{
|
||||||
dispatchArgs.Add(StrongNameOptions.StrongNameKeyPath);
|
dispatchArgs.Add(StrongNameOptions.StrongNameKeyPath);
|
||||||
|
|
@ -123,7 +123,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Internal
|
||||||
var toolName = typeof(Design.Program).GetTypeInfo().Assembly.GetName().Name;
|
var toolName = typeof(Design.Program).GetTypeInfo().Assembly.GetName().Name;
|
||||||
var dispatchCommand = DotnetToolDispatcher.CreateDispatchCommand(
|
var dispatchCommand = DotnetToolDispatcher.CreateDispatchCommand(
|
||||||
dispatchArgs,
|
dispatchArgs,
|
||||||
TargetFramework,
|
runtimeContext.TargetFramework,
|
||||||
Configuration,
|
Configuration,
|
||||||
outputPath: outputPaths.RuntimeOutputPath,
|
outputPath: outputPaths.RuntimeOutputPath,
|
||||||
buildBasePath: null,
|
buildBasePath: null,
|
||||||
|
|
@ -144,12 +144,10 @@ namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Internal
|
||||||
ProjectPath = GetProjectPath(Options.ProjectArgument.Value);
|
ProjectPath = GetProjectPath(Options.ProjectArgument.Value);
|
||||||
Configuration = ConfigurationOption.Value() ?? DotNet.Cli.Utils.Constants.DefaultConfiguration;
|
Configuration = ConfigurationOption.Value() ?? DotNet.Cli.Utils.Constants.DefaultConfiguration;
|
||||||
|
|
||||||
if (!FrameworkOption.HasValue())
|
if (FrameworkOption.HasValue())
|
||||||
{
|
{
|
||||||
Application.Error.WriteLine($"Option {FrameworkOption.Template} does not have a value.");
|
TargetFramework = NuGetFramework.Parse(FrameworkOption.Value());
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
TargetFramework = NuGetFramework.Parse(FrameworkOption.Value());
|
|
||||||
|
|
||||||
if (!OutputPathOption.HasValue())
|
if (!OutputPathOption.HasValue())
|
||||||
{
|
{
|
||||||
|
|
@ -188,18 +186,28 @@ namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Internal
|
||||||
private ProjectContext GetRuntimeContext()
|
private ProjectContext GetRuntimeContext()
|
||||||
{
|
{
|
||||||
var workspace = new BuildWorkspace(ProjectReaderSettings.ReadFromEnvironment());
|
var workspace = new BuildWorkspace(ProjectReaderSettings.ReadFromEnvironment());
|
||||||
|
var projectContexts = ProjectContext.CreateContextForEachFramework(ProjectPath).ToArray();
|
||||||
var projectContext = workspace.GetProjectContext(ProjectPath, TargetFramework);
|
ProjectContext projectContext;
|
||||||
if (projectContext == null)
|
if (TargetFramework != null)
|
||||||
{
|
{
|
||||||
Debug.Assert(FrameworkOption.HasValue());
|
projectContext = projectContexts.FirstOrDefault(context => context.TargetFramework == TargetFramework);
|
||||||
throw new InvalidOperationException($"Project '{ProjectPath}' does not support framework: {FrameworkOption.Value()}");
|
if (projectContext == null)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException($"Project '{ProjectPath}' does not support framework: {FrameworkOption.Value()}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (projectContexts.Length == 1)
|
||||||
|
{
|
||||||
|
projectContext = projectContexts[0];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException($"Project '{ProjectPath}' targets multiple frameworks. Specify one using '{FrameworkOption.Template}.");
|
||||||
}
|
}
|
||||||
|
|
||||||
var runtimeContext = workspace.GetRuntimeContext(
|
return workspace.GetRuntimeContext(
|
||||||
projectContext,
|
projectContext,
|
||||||
RuntimeEnvironmentRidExtensions.GetAllCandidateRuntimeIdentifiers());
|
RuntimeEnvironmentRidExtensions.GetAllCandidateRuntimeIdentifiers());
|
||||||
return runtimeContext;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -69,22 +69,6 @@ Options:
|
||||||
result.Error.Split(new[] { Environment.NewLine }, StringSplitOptions.None).First());
|
result.Error.Split(new[] { Environment.NewLine }, StringSplitOptions.None).First());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void RunPrintsError_IfFrameworkIfNotSpecified()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
var expected = "Option -f|--framework does not have a value.";
|
|
||||||
var args = new string[0];
|
|
||||||
|
|
||||||
// Act
|
|
||||||
var result = Execute(args);
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Assert.Equal(1, result.ExitCode);
|
|
||||||
Assert.Empty(result.Out);
|
|
||||||
Assert.Equal(expected, result.Error.Trim());
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void RunPrintsError_IfOutputPathIfNotSpecified()
|
public void RunPrintsError_IfOutputPathIfNotSpecified()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue