Updating csproject files...

Posts   
 
    
simmotech
User
Posts: 1024
Joined: 01-Feb-2006
# Posted on: 22-Feb-2008 11:00:17   

No matter what I do, the csproj file always gets updated even if no new files are added.

I have both StoreTimeLastGeneratedIntoProject and CleanUpVsNetProjects set to false so no changes are made to the file but the fact that it is writing to the file at all means that Visual Studio wants to reload the project again.

Am I missing a setting somewhere?

Would be it be a simple fix to not write to the file if what is written is identical to what is read (I seem to recall a forum thread that it is all Xml sections)?

Cheers Simon

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39905
Joined: 17-Aug-2003
# Posted on: 22-Feb-2008 11:28:59   

Using a diff tool, what's the difference between the files?

Frans Bouma | Lead developer LLBLGen Pro
simmotech
User
Posts: 1024
Joined: 01-Feb-2006
# Posted on: 22-Feb-2008 12:22:53   

Otis wrote:

Using a diff tool, what's the difference between the files?

Hi Frans

Files are exactly equal.

I've just created my first task performer. simple_smile which is basically a copy of the ProjectFileCreator class from the SDK but I now check whether the Xml output from AlterProjectFileContents is identical to what it started with. If it is then it returns null and the Perform method detects this and sets actionTypeForLog to "preserved" and skips the file update.

The SDK docs say "add a task (or alter a task tag) tag to the task definitions and define your assembly and your class as the task performer for that particular task" but they don't describe how exactly to do that and the preset file doesn't seem to have any assembly info. What am I missing?

Cheers Simon

simmotech
User
Posts: 1024
Joined: 01-Feb-2006
# Posted on: 22-Feb-2008 15:44:08   

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

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39905
Joined: 17-Aug-2003
# Posted on: 22-Feb-2008 16:48:15   

Thanks for the info! smile . I'll change the taskperformer so the taskperformer won't update the file and the filedate therefore won't update.

For the people who wonder where to set the taskperformer in the tasks: in the preset. Select the task and change the parameter in the task which specifies the taskperformer.

Frans Bouma | Lead developer LLBLGen Pro