Visual Studio and XML command line parameters
-
(Yes, I meant to put this here, no real reason.) I discovered this this week. Unsure anyone else has noticed it or has any idea of how to avoid it. I'm working on a command-line program which will require XML in a parameter. I stored an example XML parameter in VS (2010 and 2015) for debugging. It seemed OK the first day, but things went awry when I ran it the following day. This evening I whipped up a little demonstration. I set the debug parameter such:
"<ArgTest><Parameter>Value</Parameter></ArgTest>"
In ArgTest.csproj.user, it looks good:
<StartArguments>"<ArgTest><Parameter>Value</Parameter></ArgTest>"</StartArguments>
And on first run, the output is good:
<ArgTest><Parameter>Value</Parameter></ArgTest>
Value
"c:\Project\ArgTest\bin\Debug\ArgTest.exe" "<ArgTest><Parameter>Value</Parameter></ArgTest>"
ValueBut, save, close, and re-open the solution, and the parameter somehow gains a default namespace which then gets mangled by the system:
"Value"
Value
'http' is an unexpected token. The expected token is '"' or '''. Line 1, position 16.
"c:\Project\ArgTest\bin\Debug\ArgTest.exe" "Value"
Not foundSome of you will be surprised by the "Not found", but I'm not, I expected it once I saw the problem. Obviously, Visual Studio saves the .user file inappropriately, but that doesn't explain the addition of the namespace. Very weird.
namespace CP
{
public static partial class ArgTest
{
static int
Main
(
string[] args
)
{
int result = 0 ;System.Xml.XmlDocument doc = new System.Xml.XmlDocument() ; try { System.Console.WriteLine ( args \[ 0 \] ) ; doc.LoadXml ( args \[ 0 \] ) ; System.Xml.XmlNode val = doc.DocumentElement.SelectSingleNode ( "Parameter" ) ; if ( val == null ) { System.Console.WriteLine ( "Not found" ) ; } else { System.Console.WriteLine ( val.InnerText ) ; } }
-
(Yes, I meant to put this here, no real reason.) I discovered this this week. Unsure anyone else has noticed it or has any idea of how to avoid it. I'm working on a command-line program which will require XML in a parameter. I stored an example XML parameter in VS (2010 and 2015) for debugging. It seemed OK the first day, but things went awry when I ran it the following day. This evening I whipped up a little demonstration. I set the debug parameter such:
"<ArgTest><Parameter>Value</Parameter></ArgTest>"
In ArgTest.csproj.user, it looks good:
<StartArguments>"<ArgTest><Parameter>Value</Parameter></ArgTest>"</StartArguments>
And on first run, the output is good:
<ArgTest><Parameter>Value</Parameter></ArgTest>
Value
"c:\Project\ArgTest\bin\Debug\ArgTest.exe" "<ArgTest><Parameter>Value</Parameter></ArgTest>"
ValueBut, save, close, and re-open the solution, and the parameter somehow gains a default namespace which then gets mangled by the system:
"Value"
Value
'http' is an unexpected token. The expected token is '"' or '''. Line 1, position 16.
"c:\Project\ArgTest\bin\Debug\ArgTest.exe" "Value"
Not foundSome of you will be surprised by the "Not found", but I'm not, I expected it once I saw the problem. Obviously, Visual Studio saves the .user file inappropriately, but that doesn't explain the addition of the namespace. Very weird.
namespace CP
{
public static partial class ArgTest
{
static int
Main
(
string[] args
)
{
int result = 0 ;System.Xml.XmlDocument doc = new System.Xml.XmlDocument() ; try { System.Console.WriteLine ( args \[ 0 \] ) ; doc.LoadXml ( args \[ 0 \] ) ; System.Xml.XmlNode val = doc.DocumentElement.SelectSingleNode ( "Parameter" ) ; if ( val == null ) { System.Console.WriteLine ( "Not found" ) ; } else { System.Console.WriteLine ( val.InnerText ) ; } }
Seems like you need to manually edit the
.csproj.user
file to wrap the arguments in a CDATA section: Visual Studio changes debug xml Command line arguments - Stack Overflow[^] Unfortunately, you'll have to repeat that every time you change a project setting.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
Seems like you need to manually edit the
.csproj.user
file to wrap the arguments in a CDATA section: Visual Studio changes debug xml Command line arguments - Stack Overflow[^] Unfortunately, you'll have to repeat that every time you change a project setting.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
This program doesn't warrant that amount of effort. :D I'll have to ensure that my command line parser can remove the namespace when present, but this program doesn't use that anyway.