/* * Method: ValidateHasParameter * * Validates that the the given ToolTaskExtension's command line contains the indicated * parameter. Returns the index of the parameter that matched. * */ internal static int ValidateHasParameter(ToolTaskExtension t, string parameter, bool useResponseFile) { CommandLineBuilderExtension b = new CommandLineBuilderExtension(); if (useResponseFile) t.AddResponseFileCommands(b); else t.AddCommandLineCommands(b); string cl = b.ToString(); string msg = String.Format("Command-line = [{0}]\r\n", cl); msg += String.Format(" Searching for [{0}]\r\n", parameter); string[] pieces = Parse(cl); int i = 0; foreach (string s in pieces) { msg += String.Format(" Parm = [{0}]\r\n", s); if (s == parameter) { return i; } i++; } msg += "Not found!\r\n"; Console.WriteLine(msg); Assert.Fail(msg); // Could not find the parameter. return 0; }
public void ARFC (CommandLineBuilderExtension commandLine) { base.AddResponseFileCommands (commandLine); #if !NET_4_0 string s = commandLine.ToString (); if (s.Length == 6) Assert.AreEqual ("/sdk:2", s); else Assert.AreEqual ("/sdk:2 ", s.Substring (0, 7)); BindingFlags flags = BindingFlags.Instance | BindingFlags.NonPublic; PropertyInfo pi = typeof (CommandLineBuilderExtension).GetProperty ("CommandLine", flags); System.Text.StringBuilder sb = (System.Text.StringBuilder) pi.GetValue (commandLine, null); sb.Length = 0; if (s.Length > 6) sb.Append (s.Substring (7)); #endif }
public void AppendItemWithInvalidBooleanAttribute() { Assert.Throws<ArgumentException>(() => { // Construct the task item. TaskItem i = new TaskItem(); i.ItemSpec = "MyResource.bmp"; i.SetMetadata("Name", "Kenny"); i.SetMetadata("Private", "Yes"); // This is our flag. CommandLineBuilderExtension c = new CommandLineBuilderExtension(); // Validate that a legitimate bool works first. try { c.AppendSwitchIfNotNull ( "/myswitch:", new ITaskItem[] { i }, new string[] { "Name", "Private" }, new bool[] { false, true } ); Assert.Equal(@"/myswitch:MyResource.bmp,Kenny,Private", c.ToString()); } catch (ArgumentException e) { Assert.True(false, "Got an unexpected exception:" + e.Message); } // Now try a bogus boolean. i.SetMetadata("Private", "Maybe"); // This is our flag. c.AppendSwitchIfNotNull ( "/myswitch:", new ITaskItem[] { i }, new string[] { "Name", "Private" }, new bool[] { false, true } ); // <-- Expect an ArgumentException here. } ); }
/// <summary> /// Fills the provided CommandLineBuilderExtension with all the command line options used when /// executing this tool that can go into a response file. /// </summary> /// <comments> /// ResGen 3.5 and earlier doesn't support response files, but ResGen 4.0 and later does. /// </comments> /// <param name="commandLine">Gets filled with command line options</param> protected internal override void AddResponseFileCommands(CommandLineBuilderExtension commandLine) { string pathToResGen = GenerateResGenFullPath(); // Only do anything if we can actually use response files if ( pathToResGen != null && !pathToResGen.Equals(ToolLocationHelper.GetPathToDotNetFrameworkSdkFile("resgen.exe", TargetDotNetFrameworkVersion.Version35), StringComparison.OrdinalIgnoreCase) && String.IsNullOrEmpty(StronglyTypedLanguage) ) { // 4.0 resgen.exe does support response files, so we can return the resgen arguments here! CommandLineBuilderExtension resGenArguments = new CommandLineBuilderExtension(); GenerateResGenCommands(resGenArguments, true /* arguments must be line-delimited */); commandLine.AppendTextUnquoted(resGenArguments.ToString()); } else { // return nothing -- if it's not 4.0, or if we're building strongly typed resources, we assume that, // as far as ToolTask is concerned at least, response files are not supported. } }
public void TestDefineConstants2 () { CscExtended csc = new CscExtended (); CommandLineBuilderExtension c1 = new CommandLineBuilderExtension (); CommandLineBuilderExtension c2 = new CommandLineBuilderExtension (); csc.DefineConstants = ";;;"; csc.ARFC (c1); csc.ACLC (c2); Assert.AreEqual (String.Empty, c1.ToString (), "A1"); Assert.AreEqual (String.Empty, c2.ToString (), "A2"); }
public void TestWin32Resource () { MCExtended mc = new MCExtended (); CommandLineBuilderExtension c1 = new CommandLineBuilderExtension (); CommandLineBuilderExtension c2 = new CommandLineBuilderExtension (); mc.Win32Resource = "A;B"; mc.ARFC (c1); mc.ACLC (c2); Assert.AreEqual (String.Empty, c1.ToString (), "A1"); Assert.AreEqual (String.Empty, c2.ToString (), "A2"); }
public void TestTreatWarningsAsErrors2 () { MCExtended mc = new MCExtended (); CommandLineBuilderExtension c1 = new CommandLineBuilderExtension (); CommandLineBuilderExtension c2 = new CommandLineBuilderExtension (); mc.TreatWarningsAsErrors = false; mc.ARFC (c1); mc.ACLC (c2); Assert.AreEqual ("/warnaserror-", c1.ToString (), "A1"); Assert.AreEqual (String.Empty, c2.ToString (), "A2"); }
public void TestSources () { MCExtended mc = new MCExtended (); CommandLineBuilderExtension c1 = new CommandLineBuilderExtension (); CommandLineBuilderExtension c2 = new CommandLineBuilderExtension (); mc.Sources = new ITaskItem [2] { new TaskItem ("A"), new TaskItem ("B") }; mc.ARFC (c1); mc.ACLC (c2); Assert.AreEqual ("/out:A.exe A B", c1.ToString (), "A1"); Assert.AreEqual (String.Empty, c2.ToString (), "A2"); }
public void TestOptimize2 () { MCExtended mc = new MCExtended (); CommandLineBuilderExtension c1 = new CommandLineBuilderExtension (); CommandLineBuilderExtension c2 = new CommandLineBuilderExtension (); mc.Optimize = false; mc.ARFC (c1); mc.ACLC (c2); Assert.AreEqual ("/optimize-", c1.ToString (), "A1"); Assert.AreEqual (String.Empty, c2.ToString (), "A2"); }
public void TestMainEntryPoint () { MCExtended mc = new MCExtended (); CommandLineBuilderExtension c1 = new CommandLineBuilderExtension (); CommandLineBuilderExtension c2 = new CommandLineBuilderExtension (); mc.MainEntryPoint = "A"; mc.ARFC (c1); mc.ACLC (c2); Assert.AreEqual (String.Empty, c1.ToString (), "A1"); Assert.AreEqual (String.Empty, c2.ToString (), "A2"); }
public void TestKeyContainer () { MCExtended mc = new MCExtended (); CommandLineBuilderExtension c1 = new CommandLineBuilderExtension (); CommandLineBuilderExtension c2 = new CommandLineBuilderExtension (); mc.KeyContainer = "A"; mc.ARFC (c1); mc.ACLC (c2); Assert.AreEqual ("/keycontainer:A", c1.ToString (), "A1"); Assert.AreEqual (String.Empty, c2.ToString (), "A2"); }
public void TestEmitDebugInformation2 () { MCExtended mc = new MCExtended (); CommandLineBuilderExtension c1 = new CommandLineBuilderExtension (); CommandLineBuilderExtension c2 = new CommandLineBuilderExtension (); mc.EmitDebugInformation = false; mc.ARFC (c1); mc.ACLC (c2); Assert.AreEqual ("/debug-", c1.ToString (), "A1"); Assert.AreEqual (String.Empty, c2.ToString (), "A2"); }
public void TestDefineConstants () { MCExtended mc = new MCExtended (); CommandLineBuilderExtension c1 = new CommandLineBuilderExtension (); CommandLineBuilderExtension c2 = new CommandLineBuilderExtension (); mc.DefineConstants = "A;B"; mc.ARFC (c1); mc.ACLC (c2); Assert.AreEqual (String.Empty, c1.ToString (), "A1"); Assert.AreEqual (String.Empty, c2.ToString (), "A2"); }
public void TestDefineConstants () { CscExtended csc = new CscExtended (); CommandLineBuilderExtension c1 = new CommandLineBuilderExtension (); CommandLineBuilderExtension c2 = new CommandLineBuilderExtension (); csc.DefineConstants = "A;B;;CD;;;Foo Bar"; csc.ARFC (c1); csc.ACLC (c2); Assert.AreEqual ("/define:\"A;B;CD;Foo;Bar\"", c1.ToString (), "A1"); Assert.AreEqual (String.Empty, c2.ToString (), "A2"); }
public void TestAdditionalLibPaths () { CscExtended csc = new CscExtended (); CommandLineBuilderExtension c1 = new CommandLineBuilderExtension (); CommandLineBuilderExtension c2 = new CommandLineBuilderExtension (); csc.AdditionalLibPaths = new string [2] { "A'Foo", "B" }; csc.ARFC (c1); csc.ACLC (c2); Assert.AreEqual ("/lib:\"A'Foo\",B", c1.ToString (), "A1"); Assert.AreEqual (String.Empty, c2.ToString (), "A2"); }
public void TestWarningNotAsErrors () { CscExtended csc = new CscExtended (); CommandLineBuilderExtension clbe = new CommandLineBuilderExtension (); csc.WarningsNotAsErrors = "A'B"; csc.ARFC (clbe); Assert.AreEqual ("/warnaserror-:\"A'B\"", clbe.ToString (), "A1"); }
/// <summary> /// Returns a string with those switches and other information that can't go into a response file and /// must go directly onto the command line. /// Called after ValidateParameters and SkipTaskExecution /// </summary> override protected string GenerateCommandLineCommands() { CommandLineBuilderExtension commandLineBuilder = new CommandLineBuilderExtension(); bool serializationAssemblyPathExists = false; try { if (SerializationAssembly == null) { Debug.Assert(ShouldGenerateSerializer, "GenerateCommandLineCommands() should not be called if ShouldGenerateSerializer is true and SerializationAssembly is null."); SerializationAssembly = new TaskItem[] { new TaskItem(SerializationAssemblyPath) }; } // Add the assembly switch commandLineBuilder.AppendSwitchIfNotNull("/assembly:", AssemblyFullPath); commandLineBuilder.AppendWhenTrue("/proxytypes", Bag, "UseProxyTypes"); //add the keep switch commandLineBuilder.AppendWhenTrue("/keep", Bag, "UseKeep"); // Append the references, if any. if (References != null) { foreach (string reference in References) { commandLineBuilder.AppendSwitchIfNotNull("/reference:", reference); } } //Append the Types to the command line, if any. if (Types != null) { foreach (string type in Types) { commandLineBuilder.AppendSwitchIfNotNull("/type:", type); } } // The arguments to the "/compiler" switch are themselves switches to be passed to // the compiler when generating the serialization assembly. // Add the compiler command switches for strong naming on the serialization assembly if (KeyFile != null) { commandLineBuilder.AppendNestedSwitch("/compiler:", "/keyfile:", KeyFile); } else if (KeyContainer != null) { commandLineBuilder.AppendNestedSwitch("/compiler:", "/keycontainer:", KeyContainer); } commandLineBuilder.AppendPlusOrMinusSwitch("/compiler:/delaysign", Bag, "DelaySign"); // Add the Platform switch to the compiler. if (Platform != null) { commandLineBuilder.AppendNestedSwitch("/compiler:", "/platform:", Platform); } serializationAssemblyPathExists = File.Exists(SerializationAssemblyPath); } catch (Exception e) when(ExceptionHandling.IsIoRelatedException(e)) { // Ignore the expected exceptions because they have already been logged } // Delete the assembly if it already exists. if (serializationAssemblyPathExists) { try { File.Delete(SerializationAssemblyPath); } // Of all of the exceptions that can be thrown on a File.Delete, the only ones we need to // be immediately concerned with are the UnauthorizedAccessException and the IOException // (file is in use exception). We need to make sure that the assembly is gone before we // try to produce a new one because it is possible that after some changes were made to the // base assembly, there will, in fact, not be a serialization assembly produced. We cannot // leave the earlier produced assembly around to be propagated by later processes. catch (UnauthorizedAccessException e) { Log.LogErrorWithCodeFromResources("SGen.CouldNotDeleteSerializer", SerializationAssemblyPath, e.Message); } catch (IOException e) { Log.LogErrorWithCodeFromResources("SGen.CouldNotDeleteSerializer", SerializationAssemblyPath, e.Message); } // The DirectoryNotFoundException is safely ignorable since that means that there is no // existing serialization assembly. This would be extremely unlikely anyway because we // found the serializer just a couple of milliseconds ago. } return(commandLineBuilder.ToString()); }
public void TestDelaySign2 () { MCExtended mc = new MCExtended (); CommandLineBuilderExtension c1 = new CommandLineBuilderExtension (); CommandLineBuilderExtension c2 = new CommandLineBuilderExtension (); mc.DelaySign = false; mc.ARFC (c1); mc.ACLC (c2); Assert.AreEqual ("/delaysign-", c1.ToString (), "A1"); Assert.AreEqual (String.Empty, c2.ToString (), "A2"); }
public void TestMainEntryPoint () { CscExtended csc = new CscExtended (); CommandLineBuilderExtension c1 = new CommandLineBuilderExtension (); CommandLineBuilderExtension c2 = new CommandLineBuilderExtension (); csc.MainEntryPoint = "A;B"; csc.ARFC (c1); csc.ACLC (c2); Assert.AreEqual ("/main:\"A;B\"", c1.ToString (), "A1"); Assert.AreEqual (String.Empty, c2.ToString (), "A2"); }
public void TestFileAlignment1 () { MCExtended mc = new MCExtended (); CommandLineBuilderExtension c1 = new CommandLineBuilderExtension (); CommandLineBuilderExtension c2 = new CommandLineBuilderExtension (); mc.FileAlignment = 100; mc.ARFC (c1); mc.ACLC (c2); Assert.AreEqual ("/filealign:100", c1.ToString (), "A1"); Assert.AreEqual (String.Empty, c2.ToString (), "A2"); }
public void TestReferences () { CscExtended csc = new CscExtended (); CommandLineBuilderExtension c1 = new CommandLineBuilderExtension (); CommandLineBuilderExtension c2 = new CommandLineBuilderExtension (); csc.References = new ITaskItem [2] { new TaskItem ("A;C"), new TaskItem ("B") }; csc.ARFC (c1); csc.ACLC (c2); Assert.AreEqual ("/reference:\"A;C\" /reference:B", c1.ToString (), "A1"); Assert.AreEqual (String.Empty, c2.ToString (), "A2"); }
public void TestKeyFile () { MCExtended mc = new MCExtended (); CommandLineBuilderExtension c1 = new CommandLineBuilderExtension (); CommandLineBuilderExtension c2 = new CommandLineBuilderExtension (); mc.KeyFile = "A"; mc.ARFC (c1); mc.ACLC (c2); Assert.AreEqual ("/keyfile:A /publicsign", c1.ToString (), "A1"); Assert.AreEqual (String.Empty, c2.ToString (), "A2"); }
public void TestResponseFiles () { CscExtended csc = new CscExtended (); CommandLineBuilderExtension c1 = new CommandLineBuilderExtension (); CommandLineBuilderExtension c2 = new CommandLineBuilderExtension (); csc.ResponseFiles = new ITaskItem [2] { new TaskItem ("A\'Foo"), new TaskItem ("B") }; csc.ARFC (c1); csc.ACLC (c2); Assert.AreEqual ("@\"A'Foo\" @B", c1.ToString (), "A1"); Assert.AreEqual (String.Empty, c2.ToString (), "A2"); }
public void TestNoLogo1 () { MCExtended mc = new MCExtended (); CommandLineBuilderExtension c1 = new CommandLineBuilderExtension (); CommandLineBuilderExtension c2 = new CommandLineBuilderExtension (); mc.NoLogo = true; mc.ARFC (c1); mc.ACLC (c2); Assert.AreEqual ("/nologo", c1.ToString (), "A1"); Assert.AreEqual (String.Empty, c2.ToString (), "A2"); }
public void TestWin32Resource () { CscExtended csc = new CscExtended (); CommandLineBuilderExtension c1 = new CommandLineBuilderExtension (); CommandLineBuilderExtension c2 = new CommandLineBuilderExtension (); csc.Win32Resource = "A;B"; csc.ARFC (c1); csc.ACLC (c2); Assert.AreEqual ("/win32res:\"A;B\"", c1.ToString (), "A1"); Assert.AreEqual (String.Empty, c2.ToString (), "A2"); }
public void TestOutputAssembly () { MCExtended mc = new MCExtended (); CommandLineBuilderExtension c1 = new CommandLineBuilderExtension (); CommandLineBuilderExtension c2 = new CommandLineBuilderExtension (); mc.OutputAssembly = new TaskItem ("A"); mc.ARFC (c1); mc.ACLC (c2); Assert.AreEqual ("/out:A", c1.ToString (), "A1"); Assert.AreEqual (String.Empty, c2.ToString (), "A2"); }
override protected string GenerateCommandLineCommands() { CommandLineBuilderExtension commandLineBuilder = new CommandLineBuilderExtension(); AddCommandLineCommands(commandLineBuilder); return commandLineBuilder.ToString(); }
public void TestTargetType () { MCExtended mc = new MCExtended (); CommandLineBuilderExtension c1 = new CommandLineBuilderExtension (); CommandLineBuilderExtension c2 = new CommandLineBuilderExtension (); mc.TargetType = "A"; mc.ARFC (c1); mc.ACLC (c2); Assert.AreEqual ("/target:a", c1.ToString (), "A1"); Assert.AreEqual (String.Empty, c2.ToString (), "A2"); }
public void TestAddModules () { MCExtended mc = new MCExtended (); CommandLineBuilderExtension c1 = new CommandLineBuilderExtension (); CommandLineBuilderExtension c2 = new CommandLineBuilderExtension (); mc.AddModules = new string [2] { "A", "B" }; mc.ARFC (c1); mc.ACLC (c2); Assert.AreEqual ("/addmodule:A,B", c1.ToString (), "A1"); Assert.AreEqual (String.Empty, c2.ToString (), "A2"); }
public void TestUtf8Output2 () { MCExtended mc = new MCExtended (); CommandLineBuilderExtension c1 = new CommandLineBuilderExtension (); CommandLineBuilderExtension c2 = new CommandLineBuilderExtension (); mc.Utf8Output = false; mc.ARFC (c1); mc.ACLC (c2); Assert.AreEqual (String.Empty, c1.ToString (), "A1"); Assert.AreEqual (String.Empty, c2.ToString (), "A2"); }
public void TestCodePage1 () { MCExtended mc = new MCExtended (); CommandLineBuilderExtension c1 = new CommandLineBuilderExtension (); CommandLineBuilderExtension c2 = new CommandLineBuilderExtension (); mc.CodePage = 1111; mc.ARFC (c1); mc.ACLC (c2); Assert.AreEqual ("/codepage:1111", c1.ToString (), "A1"); Assert.AreEqual (String.Empty, c2.ToString (), "A2"); }
protected override string GenerateCommandLineCommands () { CommandLineBuilderExtension clbe = new CommandLineBuilderExtension (); AddCommandLineCommands (clbe); return clbe.ToString (); }
protected override string GenerateCommandLineCommands() { CommandLineBuilderExtension extension = new CommandLineBuilderExtension(); bool flag = false; try { if (this.SerializationAssembly == null) { this.SerializationAssembly = new TaskItem[] { new TaskItem(this.SerializationAssemblyPath) }; } extension.AppendSwitchIfNotNull("/assembly:", this.AssemblyFullPath); extension.AppendWhenTrue("/proxytypes", base.Bag, "UseProxyTypes"); if (this.References != null) { foreach (string str in this.References) { extension.AppendSwitchIfNotNull("/reference:", str); } } if (this.Types != null) { foreach (string str2 in this.Types) { extension.AppendSwitchIfNotNull("/type:", str2); } } if (this.KeyFile != null) { extension.AppendNestedSwitch("/compiler:", "/keyfile:", this.KeyFile); } else if (this.KeyContainer != null) { extension.AppendNestedSwitch("/compiler:", "/keycontainer:", this.KeyContainer); } extension.AppendPlusOrMinusSwitch("/compiler:/delaysign", base.Bag, "DelaySign"); if (this.Platform != null) { extension.AppendNestedSwitch("/compiler:", "/platform:", this.Platform); } flag = File.Exists(this.SerializationAssemblyPath); } catch (Exception exception) { if (Microsoft.Build.Shared.ExceptionHandling.NotExpectedException(exception)) { throw; } } if (flag) { try { File.Delete(this.SerializationAssemblyPath); } catch (UnauthorizedAccessException exception2) { base.Log.LogErrorWithCodeFromResources("SGen.CouldNotDeleteSerializer", new object[] { this.SerializationAssemblyPath, exception2.Message }); } catch (IOException exception3) { base.Log.LogErrorWithCodeFromResources("SGen.CouldNotDeleteSerializer", new object[] { this.SerializationAssemblyPath, exception3.Message }); } } return(extension.ToString()); }