Petter Brodin
Petter Brodin

Reputation: 2189

Include XML file from package when using "Publish Web"

I have a Web API project that depends on a NuGet package. This package contains an XML file that is referenced by my application at runtime.

When I build the solution and run it in debug mode from Visual studio the file gets copied to \bin, and the application runs without problem.

When I publish the application the file doesn't get copied to the final output, and I can see that it's never been copied to the \obj folder.

I've though of adding the file reference directly to the package in the \packages folder, but this will break whenever the package version is updated.

How can I specify that the file should be copied when deploying?

Upvotes: 0

Views: 1747

Answers (2)

Stigfinnaren
Stigfinnaren

Reputation: 1

Petter Brodins answer almost work for me. And since I am new to Stackoverflow commenting i can not add a comment. In order for it to work I changed the Include to "..\Packages*\lib*.xml". But this was a life saver since i wrote a lot of documentation and couldn't get it to my swagger implementation.

Upvotes: 0

Petter Brodin
Petter Brodin

Reputation: 2189

I figured it out based on this blogpost.

I added the following to the end of the .csproj file:

<PropertyGroup>
    <CopyAllFilesToSingleFolderForPackageDependsOn>
            CustomCollectFiles;
            $(CopyAllFilesToSingleFolderForPackageDependsOn);
    </CopyAllFilesToSingleFolderForPackageDependsOn>
</PropertyGroup>


<Target Name="CustomCollectFiles">
    <Message Text="=== CustomCollectFiles ===" Importance="high" />
    <ItemGroup>
        <_CustomFiles Include="..\Packages\**\*PackageName.*.xml*" />
        <FilesForPackagingFromProject Include="%(_CustomFiles.Identity)">
            <DestinationRelativePath>bin\%(Filename)%(Extension)</DestinationRelativePath>
        </FilesForPackagingFromProject>
    </ItemGroup>
</Target>

Upvotes: 3

Related Questions