Kieren Johnstone
Kieren Johnstone

Reputation: 42013

Visual Studio/msbuild: set "Content" output directory

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..

Upvotes: 0

Views: 2596

Answers (1)

KMoraz
KMoraz

Reputation: 14164

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.

Upvotes: 1

Related Questions