DotnetCliTool references don't work if BaseIntermediateOutputPath is changed in a Directory.Build.props file.
See original GitHub issueSteps to reproduce
I have a hard time coming up with a public repro, since I don’t know of public DotnetCliTools; I’m hitting this with an internal one.
I tried debugging dotnet.exe, but build.cmd doesn’t make a dotnet.pdb and I can’t build in VS nor Rider in order to be able to run under a debugger (nor does dotnet build
work, ironically).
- Add a reference to a DotnetCliTool and a target to run it to your .csproj:
<ItemGroup>
<DotNetCliToolReference Include="MyDotnetCliTool" Version = "1.0.0" />
</ItemGroup>
<Target Name="RunMyDotnetCliToolForTargetFramework" DependsOnTargets="RunMyDotnetCliTool" BeforeTargets="BeforeBuild" Condition="'$(TargetFrameworks)' == ''" />
<Target Name="RunMyDotnetCliToolForTargetFrameworks" DependsOnTargets="RunMyDotnetCliTool" BeforeTargets="DispatchToInnerBuilds" Condition="'$(TargetFrameworks)' != ''" />
<Target Name="RunMyDotnetCliTool">
<Exec WorkingDirectory="$(MSBuildProjectDirectory)" Command="dotnet -d mydotnetclitool" />
<Message Text="Ran dotnet -d mydotnetclitool" Importance="High" />
</Target>
- Run
dotnet build
and it will find and rundotnet -d mydotnetclitool
successfully. - IMPORTANT Delete the
obj
subdirectory that the above, successful run created. - Create a Directory.Build.props, as that is the mechanism to override BaseIntermediateOutputPath.
<Project>
<PropertyGroup>
<BaseIntermediateOutputPath>c:/build_directories/obj/</BaseIntermediateOutputPath>
</PropertyGroup>
</Project>
- Create the
c:/build_directories/obj/
directory. - Run
dotnet build
and it will fail to finddotnet-mydotnetclitool.dll
when it tries to rundotnet -d mydotnetclitool
Expected behavior
That it finds the dotnet-mydotnetclitool.dll
that the DotnetCliToolReference brought down to the machine.
Persisting no-op dg to C:\projects\MyProgram\src\Project1\Project1.csproj.nuget.dgspec.json
Restore completed in 829.89 ms for C:\projects\MyProgram\src\Project1\Project1.csproj.
Restore completed in 902.96 ms for C:\projects\MyProgram\src\Project1\Project1.csproj.
Telemetry is: Enabled
projectfactory: MSBUILD_EXE_PATH = C:\Program Files\dotnet\sdk\2.2.104\MSBuild.dll
projectfactory: MSBuild project path = C:\projects\MyProgram\src\Project1\Project1.csproj
projecttoolscommandresolver: resolving commandspec from 1 Tool Libraries.
projecttoolscommandresolver: Attempting to resolve command spec from tool MyDotnetCliTool
projecttoolscommandresolver: nuget packages root:
- C:\Users\jmorton\.nuget\packages\
- C:\Program Files\dotnet\sdk\NuGetFallbackFolder
projecttoolscommandresolver: found tool lockfile at : C:\Users\jmorton\.nuget\packages\.tools\MyDotnetCliTool\1.0.0\netcoreapp2.2\project.assets.json
projecttoolscommandresolver: expect deps.json at: C:\Users\jmorton\.nuget\packages\.tools\MyDotnetCliTool\1.0.0\netcoreapp2.2\MyDotnetCliTool.deps.json
projecttoolscommandresolver: attempting to create commandspec
packagedcommandspecfactory: attempting to find command dotnet-mydotnetclitool in MyDotnetCliTool
PackagedCommandSpecFactory: Looking for prefercliruntime file at `C:\Users\jmorton\.nuget\packages\MyDotnetCliTool\1.0.0\lib\netcoreapp2.0\..\..\prefercliruntime`
Running C:\Program Files\dotnet\dotnet.exe exec --depsfile C:\Users\jmorton\.nuget\packages\.tools\MyDotnetCliTool\1.0.0\netcoreapp2.2\MyDotnetCliTool.deps.json --additionalprobingpath C:\Users\jmorton\.nuget\packages --additionalprobingpath "c:\Program Files\dotnet\sdk\NuGetFallbackFolder" C:\Users\jmorton\.nuget\packages\MyDotnetCliTool\1.0.0\lib\netcoreapp2.0\dotnet-mydotnetclitool.dll
Process ID: 12708
Ran dotnet -d mydotnetclitool
Project1 -> C:\projects\MyProgram\src\Project1\Project1\bin\Debug\netcoreapp2.1\Project1.dll
Actual behavior
It fails to find dotnet-mydotnetclitool.dll
if, and only if, the dotnet restore
was ran with BaseIntermediateOutputPath
redirected to another location:
Persisting no-op dg to C:\projects\MyProgram\src\Project1\Project1.csproj.nuget.dgspec.json
Restore completed in 829.89 ms for C:\projects\MyProgram\src\Project1\Project1.csproj.
Restore completed in 902.96 ms for C:\projects\MyProgram\src\Project1\Project1.csproj.
Telemetry is: Enabled
projectfactory: MSBUILD_EXE_PATH = C:\Program Files\dotnet\sdk\3.0.100-preview3-010431\MSBuild.dll
projectfactory: MSBuild project path = C:\projects\MyProgram\src\Project1\Project1.csproj
projecttoolscommandresolver: resolving commandspec from 1 Tool Libraries.
projecttoolscommandresolver: Attempting to resolve command spec from tool MyDotnetCliTool
projecttoolscommandresolver: nuget packages root:
projecttoolscommandresolver: failed to resolve commandspec from library.
Microsoft.DotNet.Cli.Utils.CommandUnknownException: No executable found matching command "dotnet-mydotnetclitool". See https://aka.ms/missing-command for more information.
at Microsoft.DotNet.CommandFactory.CommandFactoryUsingResolver.Create(ICommandResolverPolicy commandResolverPolicy, String commandName, IEnumerable`1 args, NuGetFramework framework, String configuration, String outputPath, String applicationName)
at Microsoft.DotNet.Cli.Program.ProcessArgs(String[] args, ITelemetry telemetryClient)
at Microsoft.DotNet.Cli.Program.Main(String[] args)
C:\projects\MyProgram\src\Project1\Project1.csproj(126,5): error MSB3073: The command "dotnet -d mydotnetclitool" exited with code 1. [C:\projects\MyProgram\src\Project1\Project1.csproj]
Build FAILED.
Environment data
dotnet --info
output:
.NET Core SDK (reflecting any global.json):
Version: 2.2.104
Commit: 73f036d4ac
Runtime Environment:
OS Name: Windows
OS Version: 10.0.17763
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\2.2.104\
Host (useful for support):
Version: 3.0.0-preview3-27503-5
Commit: 3844df9537
.NET Core SDKs installed:
2.1.202 [C:\Program Files\dotnet\sdk]
2.1.504 [C:\Program Files\dotnet\sdk]
2.1.505 [C:\Program Files\dotnet\sdk]
2.1.600 [C:\Program Files\dotnet\sdk]
2.1.601 [C:\Program Files\dotnet\sdk]
2.1.602 [C:\Program Files\dotnet\sdk]
2.2.104 [C:\Program Files\dotnet\sdk]
3.0.100-preview3-010431 [C:\Program Files\dotnet\sdk]
.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.0.0-preview3-19153-02 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.0.0-preview3-27503-5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.0.0-preview3-27504-2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
This also occurred without a global.json:
.NET Core SDK (reflecting any global.json):
Version: 3.0.100-preview3-010431
Commit: d72abce213
Runtime Environment:
OS Name: Windows
OS Version: 10.0.17763
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\3.0.100-preview3-010431\
Host (useful for support):
Version: 3.0.0-preview3-27503-5
Commit: 3844df9537
.NET Core SDKs installed:
2.1.202 [C:\Program Files\dotnet\sdk]
2.1.504 [C:\Program Files\dotnet\sdk]
2.1.505 [C:\Program Files\dotnet\sdk]
2.1.600 [C:\Program Files\dotnet\sdk]
2.1.601 [C:\Program Files\dotnet\sdk]
2.1.602 [C:\Program Files\dotnet\sdk]
2.2.104 [C:\Program Files\dotnet\sdk]
3.0.100-preview3-010431 [C:\Program Files\dotnet\sdk]
.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.0.0-preview3-19153-02 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.0.0-preview3-27503-5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.0.0-preview3-27504-2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Issue Analytics
- State:
- Created 5 years ago
- Comments:13 (1 by maintainers)
Top Results From Across the Web
The value of the property "BaseIntermediateOutputPath ...
The warning is because you are changing BaseIntermediateOutputPath within the body of the project file. Move the modification of ...
Read more >NuGet pack and restore as MSBuild targets
NET projects that use the PackageReference format, using msbuild -t:pack draws inputs from the project file to use in creating a NuGet package....
Read more >out.txt
Determine the path to the directory build props file if the user did not disable $(ImportDirectoryBuildProps) and they did not already specify an...
Read more >Out-of-band DotNet core
I am a proponent of “out-of-band” builds. This simply means that any and all files generated by the build process should not under...
Read more >Directory.Build.props take control of dependencies Dotnet Core
In this video i show how its possible manage the version of all the dependencies of the projects. All the documentation is in ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@wli3 can you take a look?
I’ve been hitting this issue with the Microsoft.XmlSerializer.Generator nuget package (version 6.0.0). The workaround from @rezna306601261 causes issues with WPF projects, you need to exclude the WPF temp projects: