Friday, 27 February 2015

Closing an xml file after reading it with Powershell



I'm making a script for publishing web applications with PowerShell.


Since I'm early in development I edit the script and the xml file alternately. Right now, the script is quite small and simple:



$settings = [xml](Get-Content c:\PublishData.xml)
$whereToProjectsAreLocally = $settings.publishing.globals.localprojectdir


But I do have a problem. Once I launch the script and check that everything works as planned I see that editing the xml file (via Notepad++) is impossible. I receive an error message that the save failed and I should check if the file is used by another application.


No other applications apart from Notepad++ and the Powershell ISE aren't using the file.


Closing the ISE does not solve the problem (closing the ISE everytime I launch the script isn't my dream solution either).


Closing the Notepad++ doesn't solve the problem either (although the newest version remembers changes even if I don't save them, but that's not the solution either).


I suppose there is something like an XmlReader in the background that I haven't closed. My question is: how do I close it after reading the content from the xml file?


Thanks :-)


No comments:

Post a Comment