nugetnuget-packagenuspec

Copy files to bin folder with .nuspec files


I have .nuspec file to create my package which contains nothing but a folder with text and other format files. I pack the folder like this:

<files>
  <file src="myData\**\*.*" target="content" copyToOutput="true" />
</files>

When I install the nuget package I want this folder to be in my bin folder/output folder so that my program can relatively reference the files present. How can I achieve this since my nuget package doesn't have any .csproj to have .target file to copy files?


Solution

  • This isn't the exact answer to your question, but I am not sure if you can achieve this without a .target file. As a workaround, you can create an empty .csproj with a .target file which shall copy the items of your content folder:

    <Project>
        <Target Name="CopyToDeployFolder" AfterTargets="Build">
            <Exec Command="xcopy.exe $(MSBuildThisFileDirectory)\..\content $(OutputPath) /e /y /i /r" />
        </Target>
        <Target Name="CopyToPublishFolder" AfterTargets="Publish">
            <Exec Command="xcopy.exe $(MSBuildThisFileDirectory)\..\content $(PublishDir) /e /y /i /r" />
        </Target>
    </Project>