question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Reading MSBuild registry properties from NuGet targets file fails in .NET Core CLI

See original GitHub issue

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 <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:open
  • Created 4 years ago
  • Reactions:5
  • Comments:6

github_iconTop GitHub Comments

3reactions
DarkGraySuncommented, Feb 17, 2020

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.)

1reaction
BamButzcommented, Jan 23, 2022
Read more comments on GitHub >

github_iconTop Results From Across the Web

NuGet Restore failing using MSBuild - visual studio
You are using MSBuild-Integrated way to restore package, for this way, there is .nuget folder (contains nuget.exe, nuget.config and ...
Read more >
dotnet restore command - .NET CLI
Learn how to restore dependencies and project-specific tools with the dotnet restore command.
Read more >
NuGet packages in the Package Registry
The Package Registry works with: NuGet CLI .NET Core CLI · Visual Studio. For documentation of the specific API endpoints that these clients...
Read more >
Fixing NuGet error: Unable to load the service index for source
Solution 1. Use a NuGet config file. ... To work around this, I am creating a new nuget.config file and populating it with...
Read more >
MSBUILD Error - exit code 2147010893
NET Core SDK 1.0 found at "C:\Program Files\dotnet\sdk\1.0.3" ... VMWarePropertiesReader - Unable to read property guestinfo.tcServerUrl.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found