Reading MSBuild registry properties from NuGet targets file fails in .NET Core CLI
See original GitHub issueI’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 <InstDir>, the dll will also be copied just fine.
I’ve also tried to get this running using a property function ([MSBuild]::GetRegistryValue
) but got the same result.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:5
- Comments:6
Top GitHub Comments
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.)
It’s not supported using
dotnet build
as stated in the docs.https://docs.microsoft.com/de-de/visualstudio/msbuild/property-functions?view=vs-2022#msbuild-getregistryvaluefromview