Skip to content

How to change the Build Action of a PhysicalFile? #312

Answered by reduckted
GFlisch asked this question in Q&A
Discussion options

You must be logged in to vote

I found this answer on Stack Overflow which gives a solution that works (with a few modifications): https://stackoverflow.com/a/24538728/4397397

ℹ️ See my comment below for an even simpler solution.

Here's a simplified solution:

private void SetBuildAction(PhysicalFile file, string buildAction)
{
    ThreadHelper.ThrowIfNotOnUIThread();

    file.GetItemInfo(out IVsHierarchy hierarchy, out uint itemId, out _);

    int result = hierarchy.SetProperty(itemId, (int)__VSHPROPID4.VSHPROPID_BuildAction, buildAction);
    if (ErrorHandler.Succeeded(result))
    {
        return;
    }

    result = hierarchy.GetProperty(itemId, (int)__VSHPROPID.VSHPROPID_BrowseObject, out object browseObject);
    

Replies: 2 comments 6 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
6 replies
@reduckted
Comment options

@madskristensen
Comment options

@GFlisch
Comment options

@madskristensen
Comment options

@reduckted
Comment options

Answer selected by GFlisch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants