0

I'm trying to achieve what markerikson was here: Visual Studio - sending "content" files to the output directory instead of a subdirectory?

The problem is, the answers there (using xcopy) is a hack. If I add a reference to the project with the content (in my case, .dlls and other data), then the content still appears under a subfolder.

How can I set Build Action -> Content and set a path for the files contained within? That propagates in such a way that if I add a reference to the containing project, the files are in the 'correct' subfolder in the referencing project's output? The content includes unmanaged code which must in the search path, i.e. in the bin folder, a subfolder will not work.

There are many content files and putting them level with my code seems crap. I have my code in a subfolder for now but it's not right..

Community
  • 1
  • 1
Kieren Johnstone
  • 41,277
  • 16
  • 94
  • 144

1 Answers1

1

Edit the .csproj (Edit Project File if you have the Productivity Power Tools installed) and change the file build action to ReferenceComWrappersToCopyLocal. Rebuild.

Ultimately all IO operations boils down to the targets defined in %FrameworkDir%\v4.0.30319\Microsoft.Common.targets

Some copy targets define DestinationFolder="$(OutDir)" (copies to output without folders) and some define DestinationFiles="@(n->'$(OutDir)%(DestinationSubDirectory)%(Filename)%(Extension)')" (keeping folder structure).

You can see that items with CopyLocal=true gets copied in _CopyOutOfDateSourceItemsToOutputDirectoryAlways with DestinationFiles, while preserving the folder structure.

KMoraz
  • 14,004
  • 3
  • 49
  • 82
  • I'll give it a go thanks - but googling doesn't turn up much explanation - can you elaborate on why? Prefer not to blindly follow instructions :) – Kieren Johnstone Nov 27 '12 at 07:33
  • MSBuild has internal calculations for all kinds of file types to be copied to output. It happens to be that 'Content' item group are one of those that determined to be copied recursively. – KMoraz Nov 27 '12 at 20:23
  • That explains why it copies recursively, it doesn't explain why something clearly intended for COM wrappers should be used here? Sorry to be pedantic, but this is clearly a hack, so worth explaining? – Kieren Johnstone Nov 27 '12 at 21:26