XMLFile Activity (UpdateAttribute) Example

Jan 13, 2014 at 12:48 PM
Looking for an example on how to use the XMLFile activity to Update the version in an Attribute of an XML File.

Example:

Source File:
<Project
        Comments = "This is the XML File "
        Name = "MY XML File"
    Version="1.0.0.600" xmlns="http://myxml.com/XML.MPJ/1">
I'm guessing the properties requiring values are
  • Action
  • File
  • XPath
  • Value?
Jan 14, 2014 at 12:35 PM
Thank You Mike for the link XmlFileClass that definitely helped. I am now running into an issues with permissions when using UpdateAttribute.

TFS2012
2012 Version of the Assemblies are being used.
All Full Control/Administrator Permissions granted to Service User for Folder
Exception Message: Error: Access to the path c:\ASDGSDF.xml' is denied.. Stack Trace: at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
at System.Xml.XmlDocument.Save(String filename)
at TfsBuildExtensions.Activities.Xml.XmlFile.TrySave() in c:\Projects\teambuild2010contrib\CustomActivities\MAIN\Source\Activities\Xml\XmlFile.cs:line 613
at TfsBuildExtensions.Activities.Xml.XmlFile.UpdateAttribute() in c:\Projects\teambuild2010contrib\CustomActivities\MAIN\Source\Activities\Xml\XmlFile.cs:line 363
at TfsBuildExtensions.Activities.Xml.XmlFile.InternalExecute() in c:\Projects\teambuild2010contrib\CustomActivities\MAIN\Source\Activities\Xml\XmlFile.cs:line 255
at TfsBuildExtensions.Activities.BaseCodeActivity.Execute(CodeActivityContext context) in c:\Projects\teambuild2010contrib\CustomActivities\MAIN\Source\Common\BaseCodeActivity.cs:line 67. (type FailingBuildException)
Exception Stack Trace: at TfsBuildExtensions.Activities.BaseCodeActivity.Execute(CodeActivityContext context) in c:\Projects\teambuild2010contrib\CustomActivities\MAIN\Source\Common\BaseCodeActivity.cs:line 89
at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager)
at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)
Jan 14, 2014 at 7:43 PM
The target file .xml had the attribute of ReadOnly so I added the File activity to update the attribute and all is well.
Coordinator
Jan 18, 2014 at 9:22 AM
thanks for the feedback. i think the task should handle that. i'll update it.

mike
Coordinator
Jan 18, 2014 at 9:25 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Coordinator
Feb 9, 2014 at 4:53 PM
Resolved with changeset 87264: XMLFile Activity should handle readonly files
Marked as answer by mikeFourie on 2/9/2014 at 9:53 AM