How to tell nuget to add package resource files as links, and not copy them into project directory

前端 未结 1 568
离开以前
离开以前 2021-01-04 11:53

Intro (how to pack resources into a nuget package)

To pack some resource files into a nuget package, what one would normally do, is the following.

Put all

相关标签:
1条回答
  • 2021-01-04 12:35

    Since NuGet currently does not support this out of the box your options are either to use PowerShell or to use a custom MSBuild target.

    PowerShell

    • Leave your resources outside of the Content directory in your NuGet package (as you already suggested).
    • Add the file link using PowerShell in the install.ps1.

    You should be able to avoid the project reload prompt if you use the Visual Studio object model (EnvDTE). I would take a look at Project.ProjectItems.AddFromFile(...) to see if that works for you.

    MSBuild target

    • NuGet supports adding an import statement into a project that points to an MSBuild .props and/or .targets file. So you could put your resources into the tools directory of your NuGet package and reference them from a custom MSBuild .props/.targets file.

    Typically the custom .props and .targets are used to customise the build process. However they are just MSBuild project files so you could add items for your resources into these project files.

    Note that .props are imported at the start of the project file when a NuGet package is installed, whilst .targets are imported at the end of the project.

    Customising NuGet

    Another option, which would take more work, would be to modify NuGet to support what you want to do.

    0 讨论(0)
提交回复
热议问题