Skip to content
This repository was archived by the owner on Jan 8, 2019. It is now read-only.

Commit d07c8cc

Browse files
committed
specify full path for dotnet, when running dotnet compile-fsc
fix #65 but ref dotnet/msbuild#1669 to resolve correct dotnet host
1 parent 51f82bd commit d07c8cc

File tree

4 files changed

+116
-1
lines changed

4 files changed

+116
-1
lines changed

src/FSharp.NET.Sdk/build/FSharp.NET.Core.Sdk.targets

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,18 @@ this file.
123123
<!--STEP2 Create the dotnet-compile-fsc response file-->
124124
<PropertyGroup>
125125
<DotnetCompileFscResponseFilePath>$(_IntermediateOutputPathFull)dotnet-compile.rsp</DotnetCompileFscResponseFilePath>
126+
127+
<!-- ref https://github.com/Microsoft/msbuild/issues/1669
128+
the dotnet in PATH can be different from the dotnet who run msbuild,
129+
so i need to specify the full path. -->
130+
<_DotNetHostExecutableName>$(MSBuildExtensionsPath)/../../dotnet</_DotNetHostExecutableName>
131+
<_DotNetHostExecutableName Condition=" '$(OS)' == 'Windows_NT' ">$(_DotNetHostExecutableName).exe</_DotNetHostExecutableName>
126132
</PropertyGroup>
127133

128134
<WriteLinesToFile File="$(DotnetCompileFscResponseFilePath)" Lines="@(DotnetCompileFscResponseLines)" Overwrite="True" />
129135

130136
<!--STEP3 HACK: invoke dotnet-compile-fsc because already works-->
131-
<Exec Command='dotnet compile-fsc "@$(DotnetCompileFscResponseFilePath)" ' />
137+
<Exec Command='"$(_DotNetHostExecutableName)" compile-fsc "@$(DotnetCompileFscResponseFilePath)" ' />
132138
</Target>
133139

134140
<!--End Required Task by .Common.target-->

test/dotnet-new.Tests/CommonScenarioTests.cs

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,5 +131,79 @@ public void TestPathWithBlank()
131131
.Execute($"build {LogArgs}")
132132
.Should().Pass();
133133
}
134+
135+
private string GetCurrentRID()
136+
{
137+
var rootPath = Temp.CreateDirectory().Path;
138+
139+
Func<string,TestCommand> test = n => new TestCommand(n) { WorkingDirectory = rootPath };
140+
141+
var result = test("dotnet").ExecuteWithCapturedOutput($"--info");
142+
143+
result.Should().Pass();
144+
145+
var dotnetInfo = result.StdOut;
146+
147+
string rid =
148+
dotnetInfo
149+
.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)
150+
.Select(s => s.Trim())
151+
.Where(s => s.StartsWith("RID:"))
152+
.Select(s => s.Replace("RID:", "").Trim())
153+
.FirstOrDefault();
154+
155+
return rid;
156+
}
157+
158+
private void CreateNoopExe(string intoDir, string name, bool fail = false)
159+
{
160+
var rootPath = Temp.CreateDirectory().Path;
161+
162+
TestAssets.CopyDirTo("Noop", rootPath);
163+
164+
Func<string,TestCommand> test = n => new TestCommand(n) { WorkingDirectory = rootPath };
165+
166+
string rid = GetCurrentRID();
167+
string msbuildArgs = $"/p:AssemblyName={name} " + (fail? "/p:Fail=true" : "");
168+
169+
test("dotnet")
170+
.Execute($"restore -r {rid} --no-cache {LogArgs} {RestoreSourcesArgs(NugetConfigSources)} {RestoreProps()} {msbuildArgs}")
171+
.Should().Pass();
172+
173+
test("dotnet")
174+
.Execute($"publish -r {rid} -o \"{intoDir}\" {msbuildArgs}")
175+
.Should().Pass();
176+
}
177+
178+
[Fact]
179+
public void DifferentDotnetInPATH()
180+
{
181+
var rootPath = Temp.CreateDirectory().Path;
182+
183+
var fakeDotnetDir = Path.Combine(rootPath, "dotnetsdk");
184+
185+
Directory.CreateDirectory(fakeDotnetDir);
186+
CreateNoopExe(fakeDotnetDir, "dotnet", fail : true);
187+
188+
var appDir = Path.Combine(rootPath, "TestApp");
189+
190+
TestAssets.CopyDirTo("TestLibrary", appDir);
191+
TestAssets.CopyDirTo("TestSuiteProps", appDir);
192+
193+
Func<string,TestCommand> test = name => new TestCommand(name) { WorkingDirectory = appDir };
194+
195+
test("dotnet")
196+
.Execute($"restore --no-cache {LogArgs} {RestoreSourcesArgs(NugetConfigSources)} {RestoreProps()}")
197+
.Should().Pass();
198+
199+
var dotnetPath = Microsoft.DotNet.Cli.Utils.Env.GetCommandPath("dotnet");
200+
201+
var newPATHEnvVar = fakeDotnetDir + Path.PathSeparator + GetEnvironmentVariable("PATH");
202+
203+
test(dotnetPath)
204+
.WithEnvironmentVariable("PATH", newPATHEnvVar)
205+
.Execute($"build {LogArgs}")
206+
.Should().Pass();
207+
}
134208
}
135209
}

test/testAssets/Noop/Program.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System;
2+
3+
namespace ConsoleApp
4+
{
5+
class Program
6+
{
7+
static int Main(string[] args)
8+
{
9+
#if FAIL
10+
return 1;
11+
#else
12+
return 0;
13+
#endif
14+
}
15+
}
16+
}

test/testAssets/Noop/noop.csproj

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>netcoreapp1.0</TargetFramework>
6+
7+
<DefineConstants Condition=" '$(Fail)' != '' ">FAIL;@(DefineConstants)</DefineConstants>
8+
</PropertyGroup>
9+
10+
<PropertyGroup Condition=" '$(SmallerFootprint)' != '' ">
11+
<TargetFramework>netstandard1.6</TargetFramework>
12+
</PropertyGroup>
13+
14+
<ItemGroup Condition=" '$(SmallerFootprint)' != '' ">
15+
<PackageReference Include="Microsoft.NETCore.Runtime.CoreCLR" Version="1.0.2" />
16+
<PackageReference Include="Microsoft.NETCore.DotNetHostPolicy" Version="1.0.1" />
17+
</ItemGroup>
18+
19+
</Project>

0 commit comments

Comments
 (0)