Add a property with path of host of msbuild
See original GitHub issueAdd a property with full path of host of msbuild
I can currently run msbuild with
msbuild.exe(net40)dotnet msbuild.dll(netcore)mono msbuild.exe(too i think, for net40)
It’s useful in target file to know who is invoking msbuild, because maybe i need to run some commands in my target files, and i want to use same host.
For example i want to run a clitool or another command in a target file
<Target Name="MyTarget">
<Exec Command='dotnet mytool arg1 arg2' />
</Target>
But that will run dotnet in PATH (global.json cannot always be used, because i can overriden in PATH, like in CI server)
set PATH=/path/to/v1/dotnet
/path/to/v2/dotnet msbuild /t:MyTarget
that will run mytool with v1 dotnet, and i dont know how to be sure is executed with v2 dotnet
Same for mono.
If a $(DotnetHost) exists, it’s possibile to do $(DotnetHost) mycmd.dll or $(DotnetHost) mycmd.exe (netcore vs net40) and that will run
mycmd.exeon win, because $(DotnetHost) is ‘’/path/to/dotnet.exe mycmd.dllon .net core win/path/to/dotnet mycmd.dllon .net core unix/mac/path/to/mono mycmd.exeon mono
I think that property should be added from msbuild, not sdk, because i can use msbuild without sdk (for simple script automation)
that also resolve workaround like (from dotnet run target file in dotnet/sdk )
<PropertyGroup>
<_DotNetHostExecutableName>dotnet</_DotNetHostExecutableName>
<_DotNetHostExecutableName Condition="$(RuntimeIdentifier.StartsWith('win'))">$(_DotNetHostExecutableName).exe</_DotNetHostExecutableName>
</PropertyGroup>
There is $(MSBuildSDKsPath) but is a subdirectory inside sdk, and i dont know if i can be sure layout will be always the same, to use relative path. And anyway doesnt fix mono or msbuild.exe
related to https://github.com/Microsoft/msbuild/issues/720 too i think, roslyn csc workaround embeddeing a .cmd/.sh inside sdk (who resolve dotnet using relative path), but that cannot be done by others.
Atm in f# (i need to run dotnet fsc.dll, with full path), i am using MSBuildExtensionsPath but i know is not future proof/hack
<_FscTask_FscToolExe>dotnet.exe</_FscTask_FscToolExe>
<_FscTask_FscToolPath>$(MSBuildExtensionsPath)/../..</_FscTask_FscToolPath>
Issue Analytics
- State:
- Created 7 years ago
- Reactions:2
- Comments:7 (5 by maintainers)

Top Related StackOverflow Question
Also, as i said before, it’s not a problem specific to fsc (that’s just an example), it’s for normal targets who want to run dotnet from msbuild (build orchestration, scripts, etc). But for sure is really high in my priority list for finalize F#, because can create bug
QUESTION: If i want to run a
dotnet somethinginside my target file? i cannot do<Exec Command="dotnet new -t lib" />because i cannot trustPATH/path/to/dotnet msbuild /t:MyTarget, happen a lot with installations in CI (download -> unzip)So ihmo is not about sdk, cli at all. It’s about msbuild. before there was only one host, now there are more, so i need to know with one. I know easy is ignore it, but mostly because the sdk/cli bundle everything, so you dont see the issue often.
I add my 5c.
My working solution for f# (work is done, i’ll send a pr really soon to update templates) is to:
FSharp.Compiler.Toolspackage is referenced by Sdk package currently used for F# FSharp.NET.SdkFSharp.Compiler.Toolspackage i define a propertyFscPath, auto-imported by props file.CoreCompileinsideFSharp.NET.Sdki just<Exec Command='dotnet "$(FscPath)" --fsc-args' />Working example in this package, but is not final name, after feedback/todo from https://github.com/Microsoft/visualfsharp/pull/2250
It works really well, minimal package size (FDD) and xplat. no special invoker (
RunCsc.cmd/.sh, who hardcode dotnet path btw, using relative position, because is important know the good path). Package contains both net40 and netcoreapp1.0, so i can run net40 when msbuild.exe or netcoreapp when isdotnet msbuildif i want (not atm). No hack, just using current msbuild extensibility (auto-import of props).Please do not embeed f# it in CLI, no special cases. is not needed.
Current packaing for f# is better than c# one ihmo:
<PackageReference Include="Microsoft.FSharp.Compiler.Sdk.netcore" Version="myversion" />and dev feed maybeTeam triage: We’ve made it this long without this, so we don’t plan to do it. Hosts are changing quite a bit with apphosts now, too.