Sdk: hostpolicy.dll not found for custom DotnetCliTool

Created on 6 Feb 2017  路  9Comments  路  Source: dotnet/sdk

Steps to reproduce

git clone https://github.com/ctaggart/sourcelink-test --single-branch --branch hostpolicy
cd sourcelink-test\src\ClassLibrary1
dotnet restore
dotnet sourcelink

Expected behavior

I get the same output as when running dotnet run when building the custom DotnetCliTool:

PS C:\Users\camer\cs\SourceLink\dotnet-sourcelink> dotnet run
SourceLink: Source Code On Demand

Usage: dotnet sourcelink [options] [command]

Options:
  -h|--help  Show help information

Commands:
  print-json  print the Source Link JSON stored in the Portable PDB file

Use "dotnet sourcelink [command] --help" for more information about a command.

Actual behavior

PS C:\Users\camer\cs\sourcelink-test\src\ClassLibrary1> dotnet sourcelink
A fatal error was encountered. The library 'hostpolicy.dll' required to execute the application was not found in 'C:\Users\camer\.nuget\packages\.tools\dotnet-sourcelink\2.0.0-b318\netc
oreapp1.0'.

Environment data

dotnet --info output:

PS C:\Users\camer\cs\sourcelink-test\src\ClassLibrary1> dotnet --info
.NET Command Line Tools (1.0.0-rc3-004530)

Product Information:
 Version:            1.0.0-rc3-004530
 Commit SHA-1 hash:  0de3338607

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.14393
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\1.0.0-rc3-004530

Most helpful comment

@ctaggart I found the issue. The nupkg for dotnet-sourcelink does not include the app's runtimeconfig.json file. As a result, it's not a valid tool. I fixed this for my local repro by copying another app's runtimeconfig.json next to the app.dll, changing file names to match.

Take a look at @blackdwarf's great explanation here which includes a csproj snippet that causes the runtimeconfig.json to be included!

All 9 comments

@ctaggart I looked at your repo, though I did not see the branch in question. However:

https://github.com/stffabi/sourcelink-test/blob/master/src/ClassLibrary1/ClassLibrary1.csproj#L3

It looks like the project is targetting netstandard1.4 and not netcoreapp1.0. The dependency closure for netstandard1.4 does not include components necessary for making the output of the project runnable. Can you try making this change?

Ideally, I'd also ask you to install the latest CLI from this repo and see if the message you get with netstandard1.4 is equally unhelpful. If so, we'll use this issue to track improving that message.

I updated the repository address in the reproduction step. The hostpolicy branch is in my fork. Yes, the project targets netstandard1.4 and I'm wanting to use a custom DotnetCliTool built using netcoreapp1.0 with it.

https://github.com/ctaggart/sourcelink-test/blob/hostpolicy/src/ClassLibrary1/ClassLibrary1.csproj#L3

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netstandard1.4</TargetFramework>
    <DebugType>Portable</DebugType>
  </PropertyGroup>
  <ItemGroup>
    <DotNetCliToolReference Include="dotnet-sourcelink">
      <Version>2.0.0-b318</Version>
    </DotNetCliToolReference>
  </ItemGroup>
</Project>

I tried switching to netcoreapp1.0 and got he same error with:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <!--<TargetFramework>netstandard1.4</TargetFramework>-->
    <TargetFramework>netcoreapp1.0</TargetFramework>
    <DebugType>Portable</DebugType>
  </PropertyGroup>
  <ItemGroup>
    <DotNetCliToolReference Include="dotnet-sourcelink">
      <Version>2.0.0-b318</Version>
    </DotNetCliToolReference>
  </ItemGroup>
</Project>

The code for dotnet-sourcelink is here:
https://github.com/ctaggart/SourceLink/blob/build/dotnet-sourcelink/

I also tried with the latest sdk & get the same error:

PS C:\Users\camer\tmp\sourcelink-test\src\ClassLibrary1> dotnet sourcelink
A fatal error was encountered. The library 'hostpolicy.dll' required to execute the application was not found in 'C:\Use
rs\camer\.nuget\packages\.tools\dotnet-sourcelink\2.0.0-b318\netcoreapp1.0'.
PS C:\Users\camer\tmp\sourcelink-test\src\ClassLibrary1> dotnet --info
.NET Command Line Tools (1.0.0-rc4-004769)

Product Information:
 Version:            1.0.0-rc4-004769
 Commit SHA-1 hash:  9cf4e9d1d0

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.14393
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\dotnet\dotnet-dev-win-x64.latest\sdk\1.0.0-rc4-004769

thanks, @ctaggart. I missed the DotnetCliToolReference in the repro.

can you dotnet -d sourcelink in the same configuration?

and share the output.

PS C:\Users\camer\tmp\sourcelink-test\src\ClassLibrary1> dotnet -d sourcelink
Telemetry is: Enabled
projectfactory: MSBUILD_EXE_PATH = C:\dotnet\dotnet-dev-win-x64.latest\sdk\1.0.0-rc4-004769\MSBuild.dll
projectfactory: MSBuild project path = C:\Users\camer\tmp\sourcelink-test\src\ClassLibrary1\ClassLibrary1.csproj
projecttoolscommandresolver: resolving commandspec from 1 Tool Libraries.
projecttoolscommandresolver: Attempting to resolve command spec from tool dotnet-sourcelink
projecttoolscommandresolver: nuget packages root:
- C:\Users\camer\.nuget\packages\
projecttoolscommandresolver: found tool lockfile at : C:\Users\camer\.nuget\packages\.tools\dotnet-sourcelink\2.0.0-b318\netcoreapp1.0\project.assets.json
projecttoolscommandresolver: expect deps.json at: C:\Users\camer\.nuget\packages\.tools\dotnet-sourcelink\2.0.0-b318\netcoreapp1.0\dotnet-sourcelink.deps.json
projecttoolscommandresolver: attempting to create commandspec
packagedcommandspecfactory: attempting to find command dotnet-sourcelink in dotnet-sourcelink
packagedcommandspecfactory: Looking for prefercliruntime file at `C:\Users\camer\.nuget\packages\dotnet-sourcelink\2.0.0-b318\lib\netcoreapp1.0\..\..\prefercliruntime`
Running C:\dotnet\dotnet-dev-win-x64.latest\dotnet.exe exec --depsfile C:\Users\camer\.nuget\packages\.tools\dotnet-sourcelink\2.0.0-b318\netcoreapp1.0\dotnet-sourcelink.deps.json --additionalprobingpath C:\Users\camer\.nuget\package
s C:\Users\camer\.nuget\packages\dotnet-sourcelink\2.0.0-b318\lib\netcoreapp1.0\dotnet-sourcelink.dll
Process ID: 7492
A fatal error was encountered. The library 'hostpolicy.dll' required to execute the application was not found in 'C:\Users\camer\.nuget\packages\.tools\dotnet-sourcelink\2.0.0-b318\netcoreapp1.0'.
PS C:\Users\camer\tmp\sourcelink-test\src\ClassLibrary1>

@ctaggart I found the issue. The nupkg for dotnet-sourcelink does not include the app's runtimeconfig.json file. As a result, it's not a valid tool. I fixed this for my local repro by copying another app's runtimeconfig.json next to the app.dll, changing file names to match.

Take a look at @blackdwarf's great explanation here which includes a csproj snippet that causes the runtimeconfig.json to be included!

Also, do note that in the latest bits available from this repo this pack bug has been fixed and the target will now pack the runtime.config.json file by default.

Thank @piotrpMSFT. This was a very frustrating issue because of the ambiguous error message. Did a dotnet pack and the runtimeconfigs file was there.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

srivatsn picture srivatsn  路  3Comments

joffreykern picture joffreykern  路  3Comments

natemcmaster picture natemcmaster  路  3Comments

dasMulli picture dasMulli  路  3Comments

gkhanna79 picture gkhanna79  路  3Comments