Project-system: Is it possible to import custom targets from a nuget package

Created on 15 Aug 2018  路  4Comments  路  Source: dotnet/project-system

I have created some custom targets for my csproj file and I'm loading it into my csproj file with an import tag. Could you also import from a nuget package? This would make version management and distribution much easier.

DiscussioQuestion

All 4 comments

Yes you can use the "build" folder in a NuGet package to auto import props/targets: https://docs.microsoft.com/en-us/nuget/reference/nuspec.

Also have a look at Directory.Build.props/targets which can simplify applying settings/targets across an entire tree: https://docs.microsoft.com/en-us/visualstudio/msbuild/customize-your-build.

@davkean I have managed to create my nuget package now.
But the prop files don't seem to load.
According to the documentation: https://docs.microsoft.com/en-us/nuget/create-packages/creating-a-package#including-msbuild-props-and-targets-in-a-package
Pre Nuget 3.x the package creates imports automatically. But from 3.x onwards the targets are available through the project.lock.json file. But this file doesn't exist anymore?

@sanderobdeijn Please ask over http://github.com/nuget/home, we don't control or own the interaction here.

For other people who have this problem I found the solution in this blog post https://natemcmaster.com/blog/2017/11/11/build-tools-in-nuget/
You have to create a dummy file like -.-
And include it in the nuspec file and target the lib folder.
Otherwise the files in the build folder won't get picked up.

Was this page helpful?
0 / 5 - 0 ratings