Managed to get it work!
Simple change really if you want to consider it for a future build:
In the AlterProjectFileContents method:
After
projectDom.InnerXml = outputText.ToString();
Add
string originalXml = projectDom.InnerXml;
Before
return projectDom;
Add
// If nothing has changed, then return null
if (string.CompareOrdinal(projectDom.InnerXml, originalXml) == 0)
{
projectDom = null;
}
In the Perform method, wrap the directory creation/xml save code like this:
if (projectDOM == null)
{
actionTypeForLog = "preserved";
}
else
{
if(!File.Exists(destinationFilename))
{
// check folders. If they don't exist, create them.
string folderToCheck = Path.GetDirectoryName(destinationFilename);
if(!Directory.Exists(folderToCheck))
{
Directory.CreateDirectory(folderToCheck);
}
}
outputWriter = new StreamWriter(destinationFilename, false, encodingToUse);
projectDOM.Save(outputWriter);
}
Cheers
Simon