SolvedHome Please provide a way to reference package ID and version in .target/.props files

It appears that there is no way to reference the package version via a macro in .target/.props files when the package is being packed. Most developers use a hack with $(MSBuildThisFileDirectory), which only works when Import is used in .vcxproj files and backfires when package files are moved into solution folders because package constructs are inserted verbatim into vcxproj.filters files and in that context $(MSBuildThisFileDirectory) refers to the location of the .vcxproj.filters file and not the original target file.

For example (and this is just one example), if I want to include a packaged library in a visible way (instead of jamming it into the additional dependencies), I would want something like this in the package:

  <ItemGroup>
    <Library Include="packages\$(NugetPkgID).$(NugetPkgVersion)\build\native\$(Platform)\$(Configuration)\mylib.lib" />
  </ItemGroup>

Instead, I'm forced now to use the package ID and version explicitly in .target files, which means that I have to update the version in multiple locations that results in extra maintenance and is quite error-prone. This approach works well with solution folders.

Can you please provide some way to reference the package ID and version in .target/.props files, similar to how you allow these in .nuspec files and MSBuild Nuget builds?

28 Answers

✔️Accepted Answer

I have the same problem. I want to have way to specify package ID and version at my .targets file.
For example:

<ItemGroup>
    <Content Include="$(NuGetPackageRoot)$(NugetPkgID)\$(NugetPkgVersion)\build\lib.so">
    </Content>
</ItemGroup>

Related Issues:

66
Home extern alias support for NuGet package references
After some experimentation and got it to work Design document From @fubar-coder on April 5 2017 15:5...
59
Home Package 'NameOfPackage' is incompatible with 'all' frameworks in project
I was surprised by this error as well Clearing NuGet cache fixed the problem. From @bsmayer on April...
38
Home Package Manager Error: Unable to load the service index for source (bad proxy settings)
For me removing the .nuget folder located in C:\Users\YourNameHere fixed the problem. ...
32
Home Unhelpful error message when incorrectly using nuspec version tag of nuget pack
This is definitely an error message which could do with some improvement It seems there are two prob...
27
Home Framework assemblies are no longer added to .nuspec when using the new .csproj project system
Is there any hope of getting this fixed soon? We're ready to merge in .csproj ports on several major...
27
Home error NU1403: The package Microsoft.CSharp.4.0.1 sha512 validation failed.
My mistake was not locking down my NuGet sources with a NuGet.Config which had this one enabled: Mic...
24
Home Add --prerelease option to dotnet add package
At the very least the error message needs to change This is the current experience: The message impl...
20
Home contentFiles (cs, compile) not working in NetStandard projects.
@emgarten Thanks for your fantastic support Two suggestions Please provide docs! NuGet is essential ...
13
Home dotnet.exe nuget push command now supports -skipDuplicate like nuget.exe did.
To clarify my expectation: #1630 should have included the required changes to dotnet Without that th...
12
Home Invoke must be called on a background thread
The error is generated by NuGet attempting to execute init.ps1 scripts for packages installed in a p...
11
Home dotnet restore on 2.1 preview1 throws error instead of warning when project files are "missing"
I have fixed that by changing Docker file from to From @christiansparre on March 8 ...
7
Home nuget.exe does not work with msbuild 12 as of 3.5.0 [fixed in 4.0.0]
.. Before NuGet CLI version 3.5.0.1938 We were using the NuGet CLI version 3.4.4.1321 When using ver...
3
Home Please provide a way to reference package ID and version in .target/.props files
I have the same problem I want to have way to specify package ID and version at my .targets file For...