In a previous post, I talked about how to manually change the project (.csproj) file to create an App.xaml and App.xaml.cs files in a Xamarin forms project. The reason for this is to be able to declare and use global application resources (styles, assets… etc.) linked to the main application file (App.cs changed to App.xaml.cs). That is, in a way, to repair a guilty XF project template that doesn't create these items by default.
Like in all development processes, when you use xamarin forms, you spend your time coding and building your projects.
In Windows, this essential build process goes through MSBuild which reads and interprets .csproj file's instructions into specific actions to compile and package your applications.
Those .csproj files are XML files containing configurations, variables and instructions… many can be manipulated in Visual Studio or Xamarin Studio. Still, some of these configurations require a deeper dive into MSBuild details. Your project, for instance, may sometimes fail to build for reasons that are difficult to trace without such dive.
Diving into MSBuild is something different from simply reading the .csproj xml instructions.
Understanding the way these instructions would be interpreted and handled by MSBuild is crucial for your investigations success.
MSBuild API to the rescue
Fortunately, MSBuild offers an API that allows you to explore or modify the build engine behavior according to your requirements.
I used this API to build a simple MSBuild browser (Windows WPF application) that allows you to examine the detailed interpretations of MSBuild to a .csproj or .vbproj file.
A project configuration browser
The browser uses the objects defined in the MSBuild Microsoft.Build.Evaluation namespace.
Three main view models of the application are used to represent MSBuild objects:
- iProject: msbuild project view model. Encapsulates the collection of:
- iProjectItemType: project item types (and actions). Each project item type encapsulating a collection of:
- iProjectItem: an item of the related type. This object encapsulates a property bag of the related MSBuild item's properties (For instance: metadata).
PropertyBag object is used to allow future application extensibility. It parses MSBuild objects' properties independently of the version referenced (the current application references MSBuild 188.8.131.52).
The result looks like this:
You can download the binaries Here…
If you are interested in extending features, you can download the source code here.