Publish doesn't copy Content

Does anyone use VS Publish or dotnet publish? I’ve found that my content is copied fine during builds, but it doesn’t get copied to the publish directory. I have the MonoGameContentReference and rely on MonoGame.Content.Builder.targets to manage the references for me, and I noticed that this line only has CopyToOutputDirectory but not CopyToPublishDirectory. I’ve tried WindowsDX and DesktopGL.Core for win-x64 and linux-x64.

I’ve followed these steps to make some progress, but this won’t scale.

  1. Add CopyToPublishDirectory but discover that CreateItem called during Build doesn’t carry over Publish.
  2. Add BeforeTargets="GetCopyToPublishDirectoryItems" but discover that targets from NuGet packages only seem to be referenced during Build, not Publish.
  3. Moved the target into my csproj and it works.

I’m not sure if I’m missing something or broke something, but it looks like a few other people on here have suggested success with dotnet publish.

After lots of testing, it looks like the Publish step will only look at the subset of packages that it requires. Thus it only loads targets files from packages with referenced libs that need to be copied to the publish folder. Since my Content.Builder package doesn’t have libs, the targets aren’t used. Now I’ll try to see if I can use this to make it work…

EDIT: After even more testing, I couldn’t reproduce this behavior. It looks like the real issue is that if you have a PackageReference in a NuGet package’s targets file, the nested dependency’s targets are only used during build but not during publish. Since I was already trying to find a different way of doing nested dependencies for compatibility, this is no longer relevant.

1 Like