Xamarin: Inspect, Visualize, and Debug Your App Live

When you’re adding the final polish before releasing your mobile app, it’s easy to get stuck in that dreaded tweak-code-debug-run cycle. For every change that you make, even the simplest ones, you have to relaunch your app on several emulators or devices to ensure it’s working properly. This is where the brand new Xamarin Inspector […]

The post Inspect, Visualize, and Debug Your App Live appeared first on Xamarin Blog.

Daniel Cazzulino: How to get the item type or build action of a file in a project

When working with Roslyn inside a Visual Studio extension, it’s not rare to need to go back and
forth between the two. In Roslyn-land, projects are mostly identified by their Guid. This is the
ProjectGuid MSBuild property of a project, available from the IVsHierarchy
VSHPROPID_ProjectIDGuid property that uniquely identifies the
project in a solution. And documents are most easily identified by their
FilePath property.

In my case, I needed to retrieve the item type (build action in the property browser), given
the things that the Roslyn API works with: project id, file path. Tell me it
doesn’t give you the creeps:

static string GetItemType (IServiceProvider services, Guid projectId, string filePath)
{
    var solution = services.GetService<SVsSolution, IVsSolution> ();

    IVsHierarchy project;
    uint itemId;
    object projectItem;
    string itemType = null;

    if (ErrorHandler.Succeeded (solution.GetProjectOfGuid (projectId, out project)) &&
        ErrorHandler.Succeeded (project.ParseCanonicalName (filePath, out itemId)) &&
        itemId != (uint)VSConstants.VSITEMID.Nil &&
        ErrorHandler.Succeeded (project.GetProperty (itemId, (int)__VSHPROPID.VSHPROPID_ExtObject, out projectItem)) &&
        projectItem != null && projectItem is ProjectItem) {
        itemType = ((ProjectItem)projectItem).Properties.Item ("ItemType").Value.ToString ();
    }

    return itemType;
}

And when searching for things like this, it’s pretty awesome to come across posts that say things like Who said building Visual Studio Extensions was hard?.

shudder