Reputation: 361
Is there a way to set these "Build Action" and "Copy to output directory" properties from code?
Upvotes: 0
Views: 1513
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:
The CopyToOutputDirectory property is an uint, and can be set to one of these __COPYTOOUTPUTSTATE
values (documentation):
Never
Always
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