I'm trying to create a NuGet package in order to redistribute a component that uses both managed and unmanaged dependencies (my.dll and mydotnetcore.dll). To copy the additional (unmanaged) file from a local installation to the output directory, we use a targets file. We read a registry key to find the local installation:
my.targets file:
<PropertyGroup>
  <InstDir>$(registry:HKEY_CURRENT_USER\SOFTWARE\myapp@LocalDir)</InstDir>
</PropertyGroup
The local file is then copied as follows:
<None Include="$(InstDir)\my.dll">
  <Visible>False</Visible>
  <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
my.nuspec file:
…
<files>
  <file src="..\mydotnetcore.dll" target="lib\NetCoreApp30\mydotnetcore.dll"/>
  <file src="build\my.targets" target="build\my.targets"/>                       
</files>
If I add this NuGet package to a .NET Core 3 (VS 2019) application and build it in the VS IDE, the application is built and both DLLs are copied to the output directory - all is well.
However when building using the .NET Core command-line (CLI) tool like so:
dotnet build
the unmanaged dependency is _not_ copied. I've found out that in this case, the InstDir property
<InstDir>$(registry:HKEY_CURRENT_USER\SOFTWARE\myapp@LocalDir)</InstDir>
seems to be empty.  Monitoring the process with Sysinternals' Process Monitor shows that the registry is not accessed. Apparently the entry is ignored. If an absolute path is entered for the property 
I've also tried to get this running using a property function ([MSBuild]::GetRegistryValue) but got the same result.
We have the same problem. The component provider Combit (combit.ListLabel25) use in its target file:
<LL25>$(registry: HKEY_CURRENT_USER\SOFTWARE\combit\cmbtll@LL25RedistDir)</LL25>
In combination with the command line tool:
dotnet publish Product.sln --configuration Release
The registry key is not found or contains an empty string. The build process fails.
(Of course I checked explicitly whether the registry key exists. The key is also found when compiling manually with Visual Studio.)
Most helpful comment
We have the same problem. The component provider Combit (combit.ListLabel25) use in its target file:
<LL25>$(registry: HKEY_CURRENT_USER\SOFTWARE\combit\cmbtll@LL25RedistDir)</LL25>In combination with the command line tool:
dotnet publish Product.sln --configuration ReleaseThe registry key is not found or contains an empty string. The build process fails.
(Of course I checked explicitly whether the registry key exists. The key is also found when compiling manually with Visual Studio.)