NuGet doesn't copy config file

2019-06-19 02:58发布

问题:

I've tried many different things now, none of which seem to work out as expected.

I would like to share an example config(or image or whatever) file with my library that someone would be able to use and derive from. I tried to default to just To do so I tried to include it in the nuget package via *.nuspec and via *.csproj. None of which worked.

For the *.nuspec part, I've tried this:

<file src="bin\$configuration$\example.mylib.config" target="lib\net45" />
<file src="bin\$configuration$\example.mylib.config" target="build" />
<file src="bin\$configuration$\example.mylib.config" target="bin" />

I've also tried this, but that only copies the file to the other projects sources, which is not what I want. I would like it to only show up in the output of the build.

<file src="bin\$configuration$\example.mylib.config" target="content" />

For the *.csproj part, I've tried to set the build action of the file to content, resource, embedded resource and None.

Is there a way at all? Is there a way to tell nuget, take this file, and behave like the dll I'm providing needs this by it's side, wherever you build?

回答1:

One thought might be to perform a config file transformation. Rather than just deploying a config file directly, you could modify the app.config or web.config on the project with a sample for the user to apply. Alternatively, as you mentioned in your comment, you could add in a Powershell script to perform the manipulations you were considering.