blinkettaro
blinkettaro

Reputation: 361

Set "Build Action" and "Copy to output directory"

Is there a way to set these "Build Action" and "Copy to output directory" properties from code?

Upvotes: 0

Views: 1513

Answers (1)

Cee McSharpface
Cee McSharpface

Reputation: 8726

Reference VSLangProj, look up property names from the FileProperties2 class, documentation here. To obtain and change properties of a file, use

var project = _applicationObject.Solution.Projects.Item(1);
var items = project.ProjectItems;
var item = items.Item(1);
var property = item.Properties.Item("BuildAction");
property.Value = prjBuildAction.prjBuildActionCompile;

To define the build action, set the BuildAction property to one of these values:

  • prjBuildActionCompile
  • prjBuildActionContent
  • prjBuildActionEmbeddedResource
  • prjBuildActionNone

The CopyToOutputDirectory property is an uint, and can be set to one of these __COPYTOOUTPUTSTATE values (documentation):

  • 0 ... Never
  • 1 ... Always
  • 2 ... PreserveNewest

This answer assumes that you are developing an extension to Visual Studio. There is another answer which achieves the same using the build engine: Set Copy to Output folder by code.

Upvotes: 2

Related Questions