Avoid using PATH to find dotnet.exe in RazorSDK tasks (#25750)

This pattern is pretty identical to what we have in other SDKs. It allows
using the SDK when dotnet isn't in the path such as the https://github.com/dotnet/aspnetcore/issues/25746.

Fixes #14432
This commit is contained in:
Pranav K 2020-09-10 16:30:55 -07:00 committed by GitHub
parent ce475cb00f
commit 5aa4a7cd41
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 36 additions and 14 deletions

View File

@ -10,7 +10,6 @@ using System.Threading;
using Microsoft.AspNetCore.Razor.Tools; using Microsoft.AspNetCore.Razor.Tools;
using Microsoft.Build.Framework; using Microsoft.Build.Framework;
using Microsoft.Build.Utilities; using Microsoft.Build.Utilities;
using Microsoft.Extensions.CommandLineUtils;
namespace Microsoft.AspNetCore.Razor.Tasks namespace Microsoft.AspNetCore.Razor.Tasks
{ {
@ -19,6 +18,7 @@ namespace Microsoft.AspNetCore.Razor.Tasks
// From https://github.com/dotnet/corefx/blob/29cd6a0b0ac2993cee23ebaf36ca3d4bce6dd75f/src/System.IO.Pipes/ref/System.IO.Pipes.cs#L93. // From https://github.com/dotnet/corefx/blob/29cd6a0b0ac2993cee23ebaf36ca3d4bce6dd75f/src/System.IO.Pipes/ref/System.IO.Pipes.cs#L93.
// Using the enum value directly as this option is not available in netstandard. // Using the enum value directly as this option is not available in netstandard.
private const PipeOptions PipeOptionCurrentUserOnly = (PipeOptions)536870912; private const PipeOptions PipeOptionCurrentUserOnly = (PipeOptions)536870912;
private string _dotnetPath;
private CancellationTokenSource _razorServerCts; private CancellationTokenSource _razorServerCts;
@ -40,7 +40,7 @@ namespace Microsoft.AspNetCore.Razor.Tasks
public string PipeName { get; set; } public string PipeName { get; set; }
protected override string ToolName => "dotnet"; protected override string ToolName => Path.GetDirectoryName(DotNetPath);
// If we're debugging then make all of the stdout gets logged in MSBuild // If we're debugging then make all of the stdout gets logged in MSBuild
protected override MessageImportance StandardOutputLoggingImportance => DebugTool ? MessageImportance.High : base.StandardOutputLoggingImportance; protected override MessageImportance StandardOutputLoggingImportance => DebugTool ? MessageImportance.High : base.StandardOutputLoggingImportance;
@ -49,17 +49,25 @@ namespace Microsoft.AspNetCore.Razor.Tasks
internal abstract string Command { get; } internal abstract string Command { get; }
protected override string GenerateFullPathToTool() protected override string GenerateFullPathToTool() => DotNetPath;
{
#if NETSTANDARD2_0
if (!string.IsNullOrEmpty(DotNetMuxer.MuxerPath))
{
return DotNetMuxer.MuxerPath;
}
#endif
// use PATH to find dotnet private string DotNetPath
return ToolExe; {
get
{
if (!string.IsNullOrEmpty(_dotnetPath))
{
return _dotnetPath;
}
_dotnetPath = Environment.GetEnvironmentVariable("DOTNET_HOST_PATH");
if (string.IsNullOrEmpty(_dotnetPath))
{
throw new InvalidOperationException("DOTNET_HOST_PATH is not set");
}
return _dotnetPath;
}
} }
protected override string GenerateCommandLineCommands() protected override string GenerateCommandLineCommands()

View File

@ -49,7 +49,7 @@
<Compile Include="..\..\Microsoft.AspNetCore.Razor.Tools\src\Client.cs"> <Compile Include="..\..\Microsoft.AspNetCore.Razor.Tools\src\Client.cs">
<Link>Shared\Client.cs</Link> <Link>Shared\Client.cs</Link>
</Compile> </Compile>
<Compile Include="$(SharedSourceRoot)CommandLineUtils\**\*.cs" /> <Compile Include="$(SharedSourceRoot)CommandLineUtils\Utilities\ArgumentEscaper.cs" />
<Content Include="_._" CopyToOutputDirectory="PreserveNewest" /> <Content Include="_._" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup> </ItemGroup>

View File

@ -98,6 +98,8 @@ Copyright (c) .NET Foundation. All rights reserved.
Debug="$(_RazorDebugTagHelperTask)" Debug="$(_RazorDebugTagHelperTask)"
DebugTool="$(_RazorDebugTagHelperTool)" DebugTool="$(_RazorDebugTagHelperTool)"
ToolAssembly="$(_RazorSdkToolAssembly)" ToolAssembly="$(_RazorSdkToolAssembly)"
ToolExe="$(_RazorSdkDotNetHostFileName)"
ToolPath="$(_RazorSdkDotNetHostDirectory)"
UseServer="$(UseRazorBuildServer)" UseServer="$(UseRazorBuildServer)"
ForceServer="$(_RazorForceBuildServer)" ForceServer="$(_RazorForceBuildServer)"
PipeName="$(_RazorBuildServerPipeName)" PipeName="$(_RazorBuildServerPipeName)"
@ -149,6 +151,8 @@ Copyright (c) .NET Foundation. All rights reserved.
Debug="$(_RazorDebugGenerateCodeTask)" Debug="$(_RazorDebugGenerateCodeTask)"
DebugTool="$(_RazorDebugGenerateCodeTool)" DebugTool="$(_RazorDebugGenerateCodeTool)"
ToolAssembly="$(_RazorSdkToolAssembly)" ToolAssembly="$(_RazorSdkToolAssembly)"
ToolExe="$(_RazorSdkDotNetHostFileName)"
ToolPath="$(_RazorSdkDotNetHostDirectory)"
UseServer="$(UseRazorBuildServer)" UseServer="$(UseRazorBuildServer)"
ForceServer="$(_RazorForceBuildServer)" ForceServer="$(_RazorForceBuildServer)"
PipeName="$(_RazorBuildServerPipeName)" PipeName="$(_RazorBuildServerPipeName)"

View File

@ -107,6 +107,8 @@ Copyright (c) .NET Foundation. All rights reserved.
<RazorGenerate <RazorGenerate
Debug="$(_RazorDebugGenerateCodeTask)" Debug="$(_RazorDebugGenerateCodeTask)"
DebugTool="$(_RazorDebugGenerateCodeTool)" DebugTool="$(_RazorDebugGenerateCodeTool)"
ToolExe="$(_RazorSdkDotNetHostFileName)"
ToolPath="$(_RazorSdkDotNetHostDirectory)"
ToolAssembly="$(_RazorSdkToolAssembly)" ToolAssembly="$(_RazorSdkToolAssembly)"
UseServer="$(UseRazorBuildServer)" UseServer="$(UseRazorBuildServer)"
ForceServer="$(_RazorForceBuildServer)" ForceServer="$(_RazorForceBuildServer)"

View File

@ -177,7 +177,9 @@ Integration with static web assets:
<MakeDir Directories="$(_ScopedCssIntermediatePath)" /> <MakeDir Directories="$(_ScopedCssIntermediatePath)" />
<RewriteCss <RewriteCss
FilesToTransform="@(_ScopedCss)" FilesToTransform="@(_ScopedCss)"
ToolAssembly="$(_RazorSdkToolAssembly)"> ToolAssembly="$(_RazorSdkToolAssembly)"
ToolExe="$(_RazorSdkDotNetHostFileName)"
ToolPath="$(_RazorSdkDotNetHostDirectory)">
</RewriteCss> </RewriteCss>
<ItemGroup> <ItemGroup>

View File

@ -36,6 +36,12 @@ Copyright (c) .NET Foundation. All rights reserved.
<_RazorSdkToolAssembly>$(RazorSdkDirectoryRoot)tools\rzc.dll</_RazorSdkToolAssembly> <_RazorSdkToolAssembly>$(RazorSdkDirectoryRoot)tools\rzc.dll</_RazorSdkToolAssembly>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(DOTNET_HOST_PATH)' == ''">
<_RazorSdkDotNetHostDirectory>$(NetCoreRoot)</_RazorSdkDotNetHostDirectory>
<_RazorSdkDotNetHostFileName>dotnet</_RazorSdkDotNetHostFileName>
<_RazorSdkDotNetHostFileName Condition="'$(OS)' == 'Windows_NT'">dotnet.exe</_RazorSdkDotNetHostFileName>
</PropertyGroup>
<!-- Resolve the RazorLangVersion based on values imported or TFM. --> <!-- Resolve the RazorLangVersion based on values imported or TFM. -->
<PropertyGroup> <PropertyGroup>
<_TargetingNETCoreApp30OrLater Condition=" '$(TargetFrameworkIdentifier)' == '.NETCoreApp' AND <_TargetingNETCoreApp30OrLater Condition=" '$(TargetFrameworkIdentifier)' == '.NETCoreApp' AND