PageRenderTime 56ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/Src/Compilers/Core/VBCSCompilerTests/CompilerServerTests.cs

https://github.com/EkardNT/Roslyn
C# | 1596 lines | 1393 code | 143 blank | 60 comment | 35 complexity | e4b11ffc9e7e8374c07687592990da4e MD5 | raw file
  1. // Copyright (c) Microsoft Open Technologies, Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Diagnostics;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Text;
  8. using ProprietaryTestResources = Microsoft.CodeAnalysis.Test.Resources.Proprietary;
  9. using Microsoft.CodeAnalysis.Test.Utilities;
  10. using Microsoft.CodeAnalysis.Text;
  11. using Roslyn.Test.Utilities;
  12. using Xunit;
  13. using Microsoft.Win32;
  14. using System.Runtime.InteropServices;
  15. using System.Reflection;
  16. namespace Microsoft.CodeAnalysis.BuildTasks.UnitTests
  17. {
  18. public class CompilerServerUnitTests : TestBase
  19. {
  20. #region Helpers
  21. private TempDirectory tempDirectory = null;
  22. public CompilerServerUnitTests()
  23. {
  24. tempDirectory = Temp.CreateDirectory();
  25. }
  26. public override void Dispose()
  27. {
  28. KillCompilerServer();
  29. base.Dispose();
  30. }
  31. private Dictionary<string, string> AddForLoggingEnvironmentVars(Dictionary<string, string> vars)
  32. {
  33. var dict = vars == null ? new Dictionary<string, string>() : vars;
  34. if (!dict.ContainsKey("RoslynCommandLineLogFile"))
  35. {
  36. dict.Add("RoslynCommandLineLogFile", typeof(CompilerServerUnitTests).Assembly.Location + ".client-server.log");
  37. }
  38. return dict;
  39. }
  40. private void KillProcess(string path)
  41. {
  42. var processes = Process.GetProcessesByName(Path.GetFileNameWithoutExtension(path));
  43. foreach (Process p in processes)
  44. {
  45. int pathSize = path.Length * 2;
  46. var exeNameBuffer = new StringBuilder(pathSize);
  47. IntPtr handle = IntPtr.Zero;
  48. try
  49. {
  50. // If the process has exited in between asking for the list and getting the handle,
  51. // this will throw an exception. We want to ignore it and keep on going with the
  52. // next process
  53. handle = p.Handle;
  54. }
  55. catch (InvalidOperationException)
  56. { }
  57. if (handle != IntPtr.Zero &&
  58. QueryFullProcessImageName(handle,
  59. 0, // Win32 path format
  60. exeNameBuffer,
  61. ref pathSize) &&
  62. string.Equals(exeNameBuffer.ToString(),
  63. path,
  64. StringComparison.OrdinalIgnoreCase))
  65. {
  66. p.Kill();
  67. p.WaitForExit();
  68. }
  69. }
  70. }
  71. /// <summary>
  72. /// Get the file path of the executable that started this process.
  73. /// </summary>
  74. /// <param name="processHandle"></param>
  75. /// <param name="flags">Should always be 0: Win32 path format.</param>
  76. /// <param name="exeNameBuffer">Buffer for the name</param>
  77. /// <param name="bufferSize">
  78. /// Size of the buffer coming in, chars written coming out.
  79. /// </param>
  80. [DllImport("Kernel32.dll", EntryPoint = "QueryFullProcessImageNameW", CharSet = CharSet.Unicode)]
  81. private static extern bool QueryFullProcessImageName(
  82. IntPtr processHandle,
  83. int flags,
  84. StringBuilder exeNameBuffer,
  85. ref int bufferSize);
  86. private static string WorkingDirectory
  87. {
  88. get
  89. {
  90. return Environment.CurrentDirectory;
  91. }
  92. }
  93. private static string msbuildExecutable;
  94. private static string MSBuildExecutable
  95. {
  96. get
  97. {
  98. if (msbuildExecutable == null)
  99. {
  100. msbuildExecutable = Path.Combine(MSBuildDirectory, "MSBuild.exe");
  101. }
  102. return msbuildExecutable;
  103. }
  104. }
  105. private static string msbuildDirectory;
  106. private static string MSBuildDirectory
  107. {
  108. get
  109. {
  110. if (msbuildDirectory == null)
  111. {
  112. var key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\MSBuild\ToolsVersions\14.0", false);
  113. if (key != null)
  114. {
  115. var toolsPath = key.GetValue("MSBuildToolsPath");
  116. if (toolsPath != null)
  117. {
  118. msbuildDirectory = toolsPath.ToString();
  119. }
  120. }
  121. }
  122. return msbuildDirectory;
  123. }
  124. }
  125. private static string CompilerServerExecutable = Path.Combine(WorkingDirectory, "VBCSCompiler.exe");
  126. private static string BuildTaskDll = Path.Combine(WorkingDirectory, "Roslyn.Compilers.BuildTasks.dll");
  127. private static string CSharpCompilerClientExecutable = Path.Combine(WorkingDirectory, "csc2.exe");
  128. private static string BasicCompilerClientExecutable = Path.Combine(WorkingDirectory, "vbc2.exe");
  129. private static string CSharpCompilerExecutable = Path.Combine(WorkingDirectory, "csc.exe");
  130. private static string BasicCompilerExecutable = Path.Combine(WorkingDirectory, "vbc.exe");
  131. // In order that the compiler server doesn't stay around and prevent future builds, we explicitly
  132. // kill it after each test.
  133. private void KillCompilerServer()
  134. {
  135. KillProcess(CompilerServerExecutable);
  136. }
  137. private ProcessResult RunCommandLineCompiler(string compilerPath, string arguments, string currentDirectory, Dictionary<string, string> additionalEnvironmentVars = null)
  138. {
  139. return ProcessLauncher.Run(compilerPath, arguments, currentDirectory, additionalEnvironmentVars: AddForLoggingEnvironmentVars(additionalEnvironmentVars));
  140. }
  141. private ProcessResult RunCommandLineCompiler(string compilerPath, string arguments, TempDirectory currentDirectory, Dictionary<string, string> filesInDirectory, Dictionary<string, string> additionalEnvironmentVars = null)
  142. {
  143. foreach (var pair in filesInDirectory)
  144. {
  145. TempFile file = currentDirectory.CreateFile(pair.Key);
  146. file.WriteAllText(pair.Value);
  147. }
  148. return RunCommandLineCompiler(compilerPath, arguments, currentDirectory.Path, additionalEnvironmentVars: AddForLoggingEnvironmentVars(additionalEnvironmentVars));
  149. }
  150. private DisposableFile GetResultFile(TempDirectory directory, string resultFileName)
  151. {
  152. return new DisposableFile(Path.Combine(directory.Path, resultFileName));
  153. }
  154. private ProcessResult RunCompilerOutput(TempFile file)
  155. {
  156. return ProcessLauncher.Run(file.Path, "", Path.GetDirectoryName(file.Path));
  157. }
  158. private static void VerifyResult(ProcessResult result)
  159. {
  160. Assert.Equal("", result.Output);
  161. Assert.Equal("", result.Errors);
  162. Assert.Equal(0, result.ExitCode);
  163. }
  164. private void VerifyResultAndOutput(ProcessResult result, TempDirectory path, string expectedOutput)
  165. {
  166. using (var resultFile = GetResultFile(path, "hello.exe"))
  167. {
  168. VerifyResult(result);
  169. var runningResult = RunCompilerOutput(resultFile);
  170. Assert.Equal(expectedOutput, runningResult.Output);
  171. }
  172. }
  173. #endregion
  174. [Fact]
  175. [Trait(Traits.Environment, Traits.Environments.VSProductInstall)]
  176. public void HelloWorldCS()
  177. {
  178. Dictionary<string, string> files =
  179. new Dictionary<string, string> {
  180. { "hello.cs",
  181. @"using System;
  182. using System.Diagnostics;
  183. class Hello
  184. {
  185. static void Main()
  186. {
  187. var obj = new Process();
  188. Console.WriteLine(""Hello, world."");
  189. }
  190. }"}};
  191. var result = RunCommandLineCompiler(CSharpCompilerClientExecutable, "/nologo hello.cs", tempDirectory, files);
  192. VerifyResultAndOutput(result, tempDirectory, "Hello, world.\r\n");
  193. }
  194. [Fact]
  195. [WorkItem(946954)]
  196. public void CompilerBinariesAreAnyCPU()
  197. {
  198. Assert.Equal(ProcessorArchitecture.MSIL, AssemblyName.GetAssemblyName(CompilerServerExecutable).ProcessorArchitecture);
  199. }
  200. /// <summary>
  201. /// This method tests that when a 64-bit compiler server loads a
  202. /// 64-bit mscorlib with /platform:x86 enabled no warning about
  203. /// emitting a refence to a 64-bit assembly is produced.
  204. /// The test should pass on x86 or amd64, but can only fail on
  205. /// amd64.
  206. /// </summary>
  207. [Fact]
  208. [Trait(Traits.Environment, Traits.Environments.VSProductInstall)]
  209. public void Platformx86MscorlibCsc()
  210. {
  211. var files = new Dictionary<string, string> { { "c.cs", "class C {}" } };
  212. var result = RunCommandLineCompiler(CSharpCompilerClientExecutable,
  213. "/nologo /t:library /platform:x86 c.cs",
  214. tempDirectory,
  215. files);
  216. VerifyResult(result);
  217. }
  218. [Fact]
  219. [Trait(Traits.Environment, Traits.Environments.VSProductInstall)]
  220. public void Platformx86MscorlibVbc()
  221. {
  222. var files = new Dictionary<string, string> { { "c.vb", "Class C\nEnd Class" } };
  223. var result = RunCommandLineCompiler(BasicCompilerClientExecutable,
  224. "/nologo /t:library /platform:x86 c.vb",
  225. tempDirectory,
  226. files);
  227. VerifyResult(result);
  228. }
  229. [Fact]
  230. [Trait(Traits.Environment, Traits.Environments.VSProductInstall)]
  231. public void ExtraMSCorLibCS()
  232. {
  233. Dictionary<string, string> files =
  234. new Dictionary<string, string> {
  235. { "hello.cs",
  236. @"using System;
  237. class Hello
  238. {
  239. static void Main()
  240. { Console.WriteLine(""Hello, world.""); }
  241. }"}};
  242. var result = RunCommandLineCompiler(CSharpCompilerClientExecutable, "/nologo /r:mscorlib.dll hello.cs", tempDirectory, files);
  243. VerifyResultAndOutput(result, tempDirectory, "Hello, world.\r\n");
  244. }
  245. [Fact]
  246. [Trait(Traits.Environment, Traits.Environments.VSProductInstall)]
  247. public void HelloWorldVB()
  248. {
  249. Dictionary<string, string> files =
  250. new Dictionary<string, string> {
  251. { "hello.vb",
  252. @"Imports System.Diagnostics
  253. Module Module1
  254. Sub Main()
  255. Dim p As New Process()
  256. Console.WriteLine(""Hello from VB"")
  257. End Sub
  258. End Module"}};
  259. var result = RunCommandLineCompiler(BasicCompilerClientExecutable, "/nologo /r:Microsoft.VisualBasic.dll hello.vb", tempDirectory, files);
  260. VerifyResultAndOutput(result, tempDirectory, "Hello from VB\r\n");
  261. }
  262. [Fact]
  263. [Trait(Traits.Environment, Traits.Environments.VSProductInstall)]
  264. public void ExtraMSCorLibVB()
  265. {
  266. Dictionary<string, string> files =
  267. new Dictionary<string, string> {
  268. { "hello.vb",
  269. @"Imports System
  270. Module Module1
  271. Sub Main()
  272. Console.WriteLine(""Hello from VB"")
  273. End Sub
  274. End Module"}};
  275. var result = RunCommandLineCompiler(BasicCompilerClientExecutable, "/nologo /r:mscorlib.dll /r:Microsoft.VisualBasic.dll hello.vb", tempDirectory, files);
  276. VerifyResultAndOutput(result, tempDirectory, "Hello from VB\r\n");
  277. }
  278. [Fact]
  279. [Trait(Traits.Environment, Traits.Environments.VSProductInstall)]
  280. public void CompileErrorsCS()
  281. {
  282. Dictionary<string, string> files =
  283. new Dictionary<string, string> {
  284. { "hello.cs",
  285. @"using System;
  286. class Hello
  287. {
  288. static void Main()
  289. { Console.WriteLine(""Hello, world."") }
  290. }"}};
  291. var result = RunCommandLineCompiler(CSharpCompilerClientExecutable, "hello.cs", tempDirectory, files);
  292. // Should output errors, but not create output file.
  293. Assert.Contains("Copyright (C) Microsoft Corporation. All rights reserved.", result.Output);
  294. Assert.Contains("hello.cs(5,42): error CS1002: ; expected\r\n", result.Output);
  295. Assert.Equal("", result.Errors);
  296. Assert.Equal(1, result.ExitCode);
  297. Assert.False(File.Exists(Path.Combine(tempDirectory.Path, "hello.exe")));
  298. }
  299. [Fact]
  300. [Trait(Traits.Environment, Traits.Environments.VSProductInstall)]
  301. public void CompileErrorsVB()
  302. {
  303. Dictionary<string, string> files =
  304. new Dictionary<string, string> {
  305. { "hellovb.vb",
  306. @"Imports System
  307. Module Module1
  308. Sub Main()
  309. Console.WriteLine(""Hello from VB"")
  310. End Sub
  311. End Class"}};
  312. var result = RunCommandLineCompiler(BasicCompilerClientExecutable, "/r:Microsoft.VisualBasic.dll hellovb.vb", tempDirectory, files);
  313. // Should output errors, but not create output file.
  314. Assert.Contains("Copyright (C) Microsoft Corporation. All rights reserved.", result.Output);
  315. Assert.Contains("hellovb.vb(3) : error BC30625: 'Module' statement must end with a matching 'End Module'.\r\n", result.Output);
  316. Assert.Contains("hellovb.vb(7) : error BC30460: 'End Class' must be preceded by a matching 'Class'.\r\n", result.Output);
  317. Assert.Equal("", result.Errors);
  318. Assert.Equal(1, result.ExitCode);
  319. Assert.False(File.Exists(Path.Combine(tempDirectory.Path, "hello.exe")));
  320. }
  321. [Fact]
  322. [Trait(Traits.Environment, Traits.Environments.VSProductInstall)]
  323. public void MissingFileErrorCS()
  324. {
  325. var result = RunCommandLineCompiler(CSharpCompilerClientExecutable, "missingfile.cs", tempDirectory, new Dictionary<string, string>());
  326. // Should output errors, but not create output file.
  327. Assert.Equal("", result.Errors);
  328. Assert.Contains("Copyright (C) Microsoft Corporation. All rights reserved.", result.Output);
  329. Assert.Contains("error CS2001: Source file", result.Output);
  330. Assert.Equal(1, result.ExitCode);
  331. Assert.False(File.Exists(Path.Combine(tempDirectory.Path, "missingfile.exe")));
  332. }
  333. [Fact]
  334. [Trait(Traits.Environment, Traits.Environments.VSProductInstall)]
  335. public void MissingReferenceErrorCS()
  336. {
  337. Dictionary<string, string> files =
  338. new Dictionary<string, string> {
  339. { "hello.cs",
  340. @"using System;
  341. class Hello
  342. {
  343. static void Main()
  344. {
  345. Console.WriteLine(""Hello, world."");
  346. }
  347. }"}};
  348. var result = RunCommandLineCompiler(CSharpCompilerClientExecutable, "/r:missing.dll hello.cs", tempDirectory, files);
  349. // Should output errors, but not create output file.
  350. Assert.Equal("", result.Errors);
  351. Assert.Contains("Copyright (C) Microsoft Corporation. All rights reserved.", result.Output);
  352. Assert.Contains("error CS0006: Metadata file", result.Output);
  353. Assert.Equal(1, result.ExitCode);
  354. Assert.False(File.Exists(Path.Combine(tempDirectory.Path, "hello.exe")));
  355. }
  356. [WorkItem(546067, "DevDiv")]
  357. [Fact]
  358. [Trait(Traits.Environment, Traits.Environments.VSProductInstall)]
  359. public void InvalidMetadataFileErrorCS()
  360. {
  361. Dictionary<string, string> files =
  362. new Dictionary<string, string> {
  363. { "Lib.cs", "public class C {}"},
  364. { "app.cs", "class Test { static void Main() {} }"},
  365. };
  366. var result = RunCommandLineCompiler(CSharpCompilerClientExecutable, "/r:Lib.cs app.cs", tempDirectory, files);
  367. // Should output errors, but not create output file.
  368. Assert.Equal("", result.Errors);
  369. Assert.Contains("Copyright (C) Microsoft Corporation. All rights reserved.", result.Output);
  370. Assert.Contains("error CS0009: Metadata file", result.Output);
  371. Assert.Equal(1, result.ExitCode);
  372. Assert.False(File.Exists(Path.Combine(tempDirectory.Path, "app.exe")));
  373. }
  374. [Fact]
  375. [Trait(Traits.Environment, Traits.Environments.VSProductInstall)]
  376. public void MissingFileErrorVB()
  377. {
  378. var result = RunCommandLineCompiler(BasicCompilerClientExecutable, "missingfile.vb", tempDirectory, new Dictionary<string, string>());
  379. // Should output errors, but not create output file.
  380. Assert.Equal("", result.Errors);
  381. Assert.Contains("Copyright (C) Microsoft Corporation. All rights reserved.", result.Output);
  382. Assert.Contains("error BC2001", result.Output);
  383. Assert.Equal(1, result.ExitCode);
  384. Assert.False(File.Exists(Path.Combine(tempDirectory.Path, "missingfile.exe")));
  385. }
  386. [Fact(), WorkItem(761131, "DevDiv")]
  387. [Trait(Traits.Environment, Traits.Environments.VSProductInstall)]
  388. public void MissingReferenceErrorVB()
  389. {
  390. Dictionary<string, string> files =
  391. new Dictionary<string, string> {
  392. { "hellovb.vb",
  393. @"Imports System.Diagnostics
  394. Module Module1
  395. Sub Main()
  396. Dim p As New Process()
  397. Console.WriteLine(""Hello from VB"")
  398. End Sub
  399. End Module"}};
  400. var result = RunCommandLineCompiler(BasicCompilerClientExecutable, "/nologo /r:Microsoft.VisualBasic.dll /r:missing.dll hellovb.vb", tempDirectory, files);
  401. // Should output errors, but not create output file.
  402. Assert.Equal("", result.Errors);
  403. Assert.Contains("error BC2017: could not find library", result.Output);
  404. Assert.Equal(1, result.ExitCode);
  405. Assert.False(File.Exists(Path.Combine(tempDirectory.Path, "hellovb.exe")));
  406. }
  407. [WorkItem(546067, "DevDiv")]
  408. [Fact]
  409. [Trait(Traits.Environment, Traits.Environments.VSProductInstall)]
  410. public void InvalidMetadataFileErrorVB()
  411. {
  412. Dictionary<string, string> files =
  413. new Dictionary<string, string> {
  414. { "Lib.vb",
  415. @"Class C
  416. End Class" },
  417. { "app.vb",
  418. @"Module M1
  419. Sub Main()
  420. End Sub
  421. End Module"}};
  422. var result = RunCommandLineCompiler(BasicCompilerClientExecutable, "/r:Lib.vb app.vb", tempDirectory, files);
  423. // Should output errors, but not create output file.
  424. Assert.Equal("", result.Errors);
  425. Assert.Contains("error BC31519", result.Output);
  426. Assert.Equal(1, result.ExitCode);
  427. Assert.False(File.Exists(Path.Combine(tempDirectory.Path, "app.exe")));
  428. }
  429. [Fact()]
  430. [WorkItem(723280, "DevDiv")]
  431. [Trait(Traits.Environment, Traits.Environments.VSProductInstall)]
  432. public void ReferenceCachingVB()
  433. {
  434. TempDirectory rootDirectory = tempDirectory.CreateDirectory("ReferenceCachingVB");
  435. // Create DLL "lib.dll"
  436. Dictionary<string, string> files =
  437. new Dictionary<string, string> {
  438. { "src1.vb",
  439. @"Imports System
  440. Public Class Library
  441. Public Shared Function GetString() As String
  442. Return ""library1""
  443. End Function
  444. End Class
  445. "}};
  446. using (var tmpFile = GetResultFile(rootDirectory, "lib.dll"))
  447. {
  448. var result = RunCommandLineCompiler(BasicCompilerClientExecutable, "src1.vb /nologo /t:library /out:lib.dll", rootDirectory, files);
  449. Assert.Equal("", result.Output);
  450. Assert.Equal("", result.Errors);
  451. Assert.Equal(0, result.ExitCode);
  452. using (var hello1_file = GetResultFile(rootDirectory, "hello1.exe"))
  453. {
  454. // Create EXE "hello1.exe"
  455. files = new Dictionary<string, string> {
  456. { "hello1.vb",
  457. @"Imports System
  458. Module Module1
  459. Public Sub Main()
  460. Console.WriteLine(""Hello1 from {0}"", Library.GetString())
  461. End Sub
  462. End Module
  463. "}};
  464. result = RunCommandLineCompiler(BasicCompilerClientExecutable, "hello1.vb /nologo /r:Microsoft.VisualBasic.dll /r:lib.dll /out:hello1.exe", rootDirectory, files);
  465. Assert.Equal("", result.Output);
  466. Assert.Equal("", result.Errors);
  467. Assert.Equal(0, result.ExitCode);
  468. // Run hello1.exe.
  469. var runningResult = RunCompilerOutput(hello1_file);
  470. Assert.Equal("Hello1 from library1\r\n", runningResult.Output);
  471. using (var hello2_file = GetResultFile(rootDirectory, "hello2.exe"))
  472. {
  473. // Create EXE "hello2.exe" referencing same DLL
  474. files = new Dictionary<string, string> {
  475. { "hello2.vb",
  476. @"Imports System
  477. Module Module1
  478. Public Sub Main()
  479. Console.WriteLine(""Hello2 from {0}"", Library.GetString())
  480. End Sub
  481. End Module
  482. "}};
  483. result = RunCommandLineCompiler(BasicCompilerClientExecutable, "hello2.vb /nologo /r:Microsoft.VisualBasic.dll /r:lib.dll /out:hello2.exe", rootDirectory, files);
  484. Assert.Equal("", result.Output);
  485. Assert.Equal("", result.Errors);
  486. Assert.Equal(0, result.ExitCode);
  487. // Run hello2.exe.
  488. runningResult = RunCompilerOutput(hello2_file);
  489. Assert.Equal("Hello2 from library1\r\n", runningResult.Output);
  490. // Change DLL "lib.dll" to something new.
  491. files =
  492. new Dictionary<string, string> {
  493. { "src2.vb",
  494. @"Imports System
  495. Public Class Library
  496. Public Shared Function GetString() As String
  497. Return ""library2""
  498. End Function
  499. Public Shared Function GetString2() As String
  500. Return ""library3""
  501. End Function
  502. End Class
  503. "}};
  504. result = RunCommandLineCompiler(BasicCompilerClientExecutable, "src2.vb /nologo /t:library /out:lib.dll", rootDirectory, files);
  505. Assert.Equal("", result.Output);
  506. Assert.Equal("", result.Errors);
  507. Assert.Equal(0, result.ExitCode);
  508. using (var hello3_file = GetResultFile(rootDirectory, "hello3.exe"))
  509. {
  510. // Create EXE "hello3.exe" referencing new DLL
  511. files = new Dictionary<string, string> {
  512. { "hello3.vb",
  513. @"Imports System
  514. Module Module1
  515. Public Sub Main()
  516. Console.WriteLine(""Hello3 from {0}"", Library.GetString2())
  517. End Sub
  518. End Module
  519. "}};
  520. result = RunCommandLineCompiler(BasicCompilerClientExecutable, "hello3.vb /nologo /r:Microsoft.VisualBasic.dll /r:lib.dll /out:hello3.exe", rootDirectory, files);
  521. Assert.Equal("", result.Output);
  522. Assert.Equal("", result.Errors);
  523. Assert.Equal(0, result.ExitCode);
  524. // Run hello3.exe. Should work.
  525. runningResult = RunCompilerOutput(hello3_file);
  526. Assert.Equal("Hello3 from library3\r\n", runningResult.Output);
  527. // Run hello2.exe one more time. Should have different output than before from updated library.
  528. runningResult = RunCompilerOutput(hello2_file);
  529. Assert.Equal("Hello2 from library2\r\n", runningResult.Output);
  530. }
  531. }
  532. }
  533. }
  534. GC.KeepAlive(rootDirectory);
  535. }
  536. [Fact()]
  537. [WorkItem(723280, "DevDiv")]
  538. [Trait(Traits.Environment, Traits.Environments.VSProductInstall)]
  539. public void ReferenceCachingCS()
  540. {
  541. TempDirectory rootDirectory = tempDirectory.CreateDirectory("ReferenceCachingCS");
  542. using (var tmpFile = GetResultFile(rootDirectory, "lib.dll"))
  543. {
  544. // Create DLL "lib.dll"
  545. Dictionary<string, string> files =
  546. new Dictionary<string, string> {
  547. { "src1.cs",
  548. @"using System;
  549. public class Library
  550. {
  551. public static string GetString()
  552. { return ""library1""; }
  553. }"}};
  554. var result = RunCommandLineCompiler(CSharpCompilerClientExecutable, "src1.cs /nologo /t:library /out:lib.dll", rootDirectory, files);
  555. Assert.Equal("", result.Output);
  556. Assert.Equal("", result.Errors);
  557. Assert.Equal(0, result.ExitCode);
  558. using (var hello1_file = GetResultFile(rootDirectory, "hello1.exe"))
  559. {
  560. // Create EXE "hello1.exe"
  561. files = new Dictionary<string, string> {
  562. { "hello1.cs",
  563. @"using System;
  564. class Hello
  565. {
  566. public static void Main()
  567. { Console.WriteLine(""Hello1 from {0}"", Library.GetString()); }
  568. }"}};
  569. result = RunCommandLineCompiler(CSharpCompilerClientExecutable, "hello1.cs /nologo /r:lib.dll /out:hello1.exe", rootDirectory, files);
  570. Assert.Equal("", result.Output);
  571. Assert.Equal("", result.Errors);
  572. Assert.Equal(0, result.ExitCode);
  573. // Run hello1.exe.
  574. var runningResult = RunCompilerOutput(hello1_file);
  575. Assert.Equal("Hello1 from library1\r\n", runningResult.Output);
  576. using (var hello2_file = GetResultFile(rootDirectory, "hello2.exe"))
  577. {
  578. var hello2exe = Temp.AddFile(hello2_file);
  579. // Create EXE "hello2.exe" referencing same DLL
  580. files = new Dictionary<string, string> {
  581. { "hello2.cs",
  582. @"using System;
  583. class Hello
  584. {
  585. public static void Main()
  586. { Console.WriteLine(""Hello2 from {0}"", Library.GetString()); }
  587. }"}};
  588. result = RunCommandLineCompiler(CSharpCompilerClientExecutable, "hello2.cs /nologo /r:lib.dll /out:hello2.exe", rootDirectory, files);
  589. Assert.Equal("", result.Output);
  590. Assert.Equal("", result.Errors);
  591. Assert.Equal(0, result.ExitCode);
  592. // Run hello2.exe.
  593. runningResult = RunCompilerOutput(hello2exe);
  594. Assert.Equal("Hello2 from library1\r\n", runningResult.Output);
  595. // Change DLL "lib.dll" to something new.
  596. files =
  597. new Dictionary<string, string> {
  598. { "src2.cs",
  599. @"using System;
  600. public class Library
  601. {
  602. public static string GetString()
  603. { return ""library2""; }
  604. public static string GetString2()
  605. { return ""library3""; }
  606. }"}};
  607. result = RunCommandLineCompiler(CSharpCompilerClientExecutable, "src2.cs /nologo /t:library /out:lib.dll", rootDirectory, files);
  608. Assert.Equal("", result.Output);
  609. Assert.Equal("", result.Errors);
  610. Assert.Equal(0, result.ExitCode);
  611. using (var hello3_file = GetResultFile(rootDirectory, "hello3.exe"))
  612. {
  613. // Create EXE "hello3.exe" referencing new DLL
  614. files = new Dictionary<string, string> {
  615. { "hello3.cs",
  616. @"using System;
  617. class Hello
  618. {
  619. public static void Main()
  620. { Console.WriteLine(""Hello3 from {0}"", Library.GetString2()); }
  621. }"}};
  622. result = RunCommandLineCompiler(CSharpCompilerClientExecutable, "hello3.cs /nologo /r:lib.dll /out:hello3.exe", rootDirectory, files);
  623. Assert.Equal("", result.Output);
  624. Assert.Equal("", result.Errors);
  625. Assert.Equal(0, result.ExitCode);
  626. // Run hello3.exe. Should work.
  627. runningResult = RunCompilerOutput(hello3_file);
  628. Assert.Equal("Hello3 from library3\r\n", runningResult.Output);
  629. // Run hello2.exe one more time. Should have different output than before from updated library.
  630. runningResult = RunCompilerOutput(hello2_file);
  631. Assert.Equal("Hello2 from library2\r\n", runningResult.Output);
  632. }
  633. }
  634. }
  635. }
  636. GC.KeepAlive(rootDirectory);
  637. }
  638. // Set up directory for multiple simultaneous compilers.
  639. private TempDirectory SetupDirectory(TempRoot root, int i)
  640. {
  641. TempDirectory dir = root.CreateDirectory();
  642. var helloFileCs = dir.CreateFile(string.Format("hello{0}.cs", i));
  643. helloFileCs.WriteAllText(string.Format(
  644. @"using System;
  645. class Hello
  646. {{
  647. public static void Main()
  648. {{ Console.WriteLine(""CS Hello number {0}""); }}
  649. }}", i));
  650. var helloFileVb = dir.CreateFile(string.Format("hello{0}.vb", i));
  651. helloFileVb.WriteAllText(string.Format(
  652. @"Imports System
  653. Module Hello
  654. Sub Main()
  655. Console.WriteLine(""VB Hello number {0}"")
  656. End Sub
  657. End Module", i));
  658. return dir;
  659. }
  660. // Run compiler in directory set up by SetupDirectory
  661. private Process RunCompilerCS(TempDirectory dir, int i)
  662. {
  663. return ProcessLauncher.StartProcess(CSharpCompilerClientExecutable, string.Format("/nologo hello{0}.cs /out:hellocs{0}.exe", i), dir.Path);
  664. }
  665. // Run compiler in directory set up by SetupDirectory
  666. private Process RunCompilerVB(TempDirectory dir, int i)
  667. {
  668. return ProcessLauncher.StartProcess(BasicCompilerClientExecutable, string.Format("/nologo hello{0}.vb /r:Microsoft.VisualBasic.dll /out:hellovb{0}.exe", i), dir.Path);
  669. }
  670. // Run output in directory set up by SetupDirectory
  671. private void RunOutput(TempRoot root, TempDirectory dir, int i)
  672. {
  673. var exeFile = root.AddFile(GetResultFile(dir, string.Format("hellocs{0}.exe", i)));
  674. var runningResult = RunCompilerOutput(exeFile);
  675. Assert.Equal(string.Format("CS Hello number {0}\r\n", i), runningResult.Output);
  676. exeFile = root.AddFile(GetResultFile(dir, string.Format("hellovb{0}.exe", i)));
  677. runningResult = RunCompilerOutput(exeFile);
  678. Assert.Equal(string.Format("VB Hello number {0}\r\n", i), runningResult.Output);
  679. }
  680. [Fact(), WorkItem(761326, "DevDiv")]
  681. [Trait(Traits.Environment, Traits.Environments.VSProductInstall)]
  682. public void MultipleSimultaneousCompiles()
  683. {
  684. // Run this many compiles simultaneously in different directories.
  685. const int numberOfCompiles = 10;
  686. TempDirectory[] directories = new TempDirectory[numberOfCompiles];
  687. Process[] processesVB = new Process[numberOfCompiles];
  688. Process[] processesCS = new Process[numberOfCompiles];
  689. for (int i = 0; i < numberOfCompiles; ++i)
  690. {
  691. directories[i] = SetupDirectory(Temp, i);
  692. }
  693. for (int i = 0; i < numberOfCompiles; ++i)
  694. {
  695. processesCS[i] = RunCompilerCS(directories[i], i);
  696. }
  697. for (int i = 0; i < numberOfCompiles; ++i)
  698. {
  699. processesVB[i] = RunCompilerVB(directories[i], i);
  700. }
  701. for (int i = 0; i < numberOfCompiles; ++i)
  702. {
  703. AssertNoOutputOrErrors(processesCS[i]);
  704. processesCS[i].WaitForExit();
  705. processesCS[i].Close();
  706. AssertNoOutputOrErrors(processesVB[i]);
  707. processesVB[i].WaitForExit();
  708. processesVB[i].Close();
  709. }
  710. for (int i = 0; i < numberOfCompiles; ++i)
  711. {
  712. RunOutput(Temp, directories[i], i);
  713. }
  714. }
  715. private void AssertNoOutputOrErrors(Process process)
  716. {
  717. Assert.Equal(string.Empty, process.StandardOutput.ReadToEnd());
  718. Assert.Equal(string.Empty, process.StandardError.ReadToEnd());
  719. }
  720. private Dictionary<string, string> GetSimpleMSBuildFiles()
  721. {
  722. // Return a dictionary with name and contents of all the files we want to create for the SimpleMSBuild test.
  723. return new Dictionary<string, string> {
  724. { "HelloSolution.sln",
  725. @"
  726. Microsoft Visual Studio Solution File, Format Version 11.00
  727. # Visual Studio 2010
  728. Project(""{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"") = ""HelloProj"", ""HelloProj.csproj"", ""{7F4CCBA2-1184-468A-BF3D-30792E4E8003}""
  729. EndProject
  730. Project(""{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"") = ""HelloLib"", ""HelloLib.csproj"", ""{C1170A4A-80CF-4B4F-AA58-2FAEA9158D31}""
  731. EndProject
  732. Project(""{F184B08F-C81C-45F6-A57F-5ABD9991F28F}"") = ""VBLib"", ""VBLib.vbproj"", ""{F21C894B-28E5-4212-8AF7-C8E0E5455737}""
  733. EndProject
  734. Global
  735. GlobalSection(SolutionConfigurationPlatforms) = preSolution
  736. Debug|Any CPU = Debug|Any CPU
  737. Debug|Mixed Platforms = Debug|Mixed Platforms
  738. Debug|x86 = Debug|x86
  739. Release|Any CPU = Release|Any CPU
  740. Release|Mixed Platforms = Release|Mixed Platforms
  741. Release|x86 = Release|x86
  742. EndGlobalSection
  743. GlobalSection(ProjectConfigurationPlatforms) = postSolution
  744. {7F4CCBA2-1184-468A-BF3D-30792E4E8003}.Debug|Any CPU.ActiveCfg = Debug|x86
  745. {7F4CCBA2-1184-468A-BF3D-30792E4E8003}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
  746. {7F4CCBA2-1184-468A-BF3D-30792E4E8003}.Debug|Mixed Platforms.Build.0 = Debug|x86
  747. {7F4CCBA2-1184-468A-BF3D-30792E4E8003}.Debug|x86.ActiveCfg = Debug|x86
  748. {7F4CCBA2-1184-468A-BF3D-30792E4E8003}.Debug|x86.Build.0 = Debug|x86
  749. {7F4CCBA2-1184-468A-BF3D-30792E4E8003}.Release|Any CPU.ActiveCfg = Release|x86
  750. {7F4CCBA2-1184-468A-BF3D-30792E4E8003}.Release|Mixed Platforms.ActiveCfg = Release|x86
  751. {7F4CCBA2-1184-468A-BF3D-30792E4E8003}.Release|Mixed Platforms.Build.0 = Release|x86
  752. {7F4CCBA2-1184-468A-BF3D-30792E4E8003}.Release|x86.ActiveCfg = Release|x86
  753. {7F4CCBA2-1184-468A-BF3D-30792E4E8003}.Release|x86.Build.0 = Release|x86
  754. {C1170A4A-80CF-4B4F-AA58-2FAEA9158D31}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
  755. {C1170A4A-80CF-4B4F-AA58-2FAEA9158D31}.Debug|Any CPU.Build.0 = Debug|Any CPU
  756. {C1170A4A-80CF-4B4F-AA58-2FAEA9158D31}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
  757. {C1170A4A-80CF-4B4F-AA58-2FAEA9158D31}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
  758. {C1170A4A-80CF-4B4F-AA58-2FAEA9158D31}.Debug|x86.ActiveCfg = Debug|Any CPU
  759. {C1170A4A-80CF-4B4F-AA58-2FAEA9158D31}.Release|Any CPU.ActiveCfg = Release|Any CPU
  760. {C1170A4A-80CF-4B4F-AA58-2FAEA9158D31}.Release|Any CPU.Build.0 = Release|Any CPU
  761. {C1170A4A-80CF-4B4F-AA58-2FAEA9158D31}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
  762. {C1170A4A-80CF-4B4F-AA58-2FAEA9158D31}.Release|Mixed Platforms.Build.0 = Release|Any CPU
  763. {C1170A4A-80CF-4B4F-AA58-2FAEA9158D31}.Release|x86.ActiveCfg = Release|Any CPU
  764. {F21C894B-28E5-4212-8AF7-C8E0E5455737}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
  765. {F21C894B-28E5-4212-8AF7-C8E0E5455737}.Debug|Any CPU.Build.0 = Debug|Any CPU
  766. {F21C894B-28E5-4212-8AF7-C8E0E5455737}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
  767. {F21C894B-28E5-4212-8AF7-C8E0E5455737}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
  768. {F21C894B-28E5-4212-8AF7-C8E0E5455737}.Debug|x86.ActiveCfg = Debug|Any CPU
  769. {F21C894B-28E5-4212-8AF7-C8E0E5455737}.Release|Any CPU.ActiveCfg = Release|Any CPU
  770. {F21C894B-28E5-4212-8AF7-C8E0E5455737}.Release|Any CPU.Build.0 = Release|Any CPU
  771. {F21C894B-28E5-4212-8AF7-C8E0E5455737}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
  772. {F21C894B-28E5-4212-8AF7-C8E0E5455737}.Release|Mixed Platforms.Build.0 = Release|Any CPU
  773. {F21C894B-28E5-4212-8AF7-C8E0E5455737}.Release|x86.ActiveCfg = Release|Any CPU EndGlobalSection
  774. GlobalSection(SolutionProperties) = preSolution
  775. HideSolutionNode = FALSE
  776. EndGlobalSection
  777. EndGlobal
  778. "},
  779. { "HelloProj.csproj",
  780. @"<?xml version=""1.0"" encoding=""utf-8""?>
  781. <Project ToolsVersion=""4.0"" DefaultTargets=""Build"" xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
  782. <UsingTask TaskName=""Microsoft.CodeAnalysis.BuildTasks.Csc"" AssemblyFile=""" + BuildTaskDll + @""" />
  783. <PropertyGroup>
  784. <Configuration Condition="" '$(Configuration)' == '' "">Debug</Configuration>
  785. <Platform Condition="" '$(Platform)' == '' "">x86</Platform>
  786. <ProductVersion>8.0.30703</ProductVersion>
  787. <SchemaVersion>2.0</SchemaVersion>
  788. <ProjectGuid>{7F4CCBA2-1184-468A-BF3D-30792E4E8003}</ProjectGuid>
  789. <OutputType>Exe</OutputType>
  790. <AppDesignerFolder>Properties</AppDesignerFolder>
  791. <RootNamespace>HelloProj</RootNamespace>
  792. <AssemblyName>HelloProj</AssemblyName>
  793. <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
  794. <TargetFrameworkProfile>Client</TargetFrameworkProfile>
  795. <FileAlignment>512</FileAlignment>
  796. </PropertyGroup>
  797. <PropertyGroup Condition="" '$(Configuration)|$(Platform)' == 'Debug|x86' "">
  798. <PlatformTarget>x86</PlatformTarget>
  799. <DebugSymbols>true</DebugSymbols>
  800. <DebugType>full</DebugType>
  801. <Optimize>false</Optimize>
  802. <OutputPath>bin\Debug\</OutputPath>
  803. <DefineConstants>DEBUG;TRACE</DefineConstants>
  804. <ErrorReport>prompt</ErrorReport>
  805. <WarningLevel>4</WarningLevel>
  806. </PropertyGroup>
  807. <PropertyGroup Condition="" '$(Configuration)|$(Platform)' == 'Release|x86' "">
  808. <PlatformTarget>x86</PlatformTarget>
  809. <DebugType>pdbonly</DebugType>
  810. <Optimize>true</Optimize>
  811. <OutputPath>bin\Release\</OutputPath>
  812. <DefineConstants>TRACE</DefineConstants>
  813. <ErrorReport>prompt</ErrorReport>
  814. <WarningLevel>4</WarningLevel>
  815. </PropertyGroup>
  816. <ItemGroup>
  817. <Reference Include=""System"" />
  818. <Reference Include=""System.Core"" />
  819. <Reference Include=""System.Xml.Linq"" />
  820. <Reference Include=""System.Xml"" />
  821. </ItemGroup>
  822. <ItemGroup>
  823. <Compile Include=""Program.cs"" />
  824. </ItemGroup>
  825. <ItemGroup>
  826. <ProjectReference Include=""HelloLib.csproj"">
  827. <Project>{C1170A4A-80CF-4B4F-AA58-2FAEA9158D31}</Project>
  828. <Name>HelloLib</Name>
  829. </ProjectReference>
  830. <ProjectReference Include=""VBLib.vbproj"">
  831. <Project>{F21C894B-28E5-4212-8AF7-C8E0E5455737}</Project>
  832. <Name>VBLib</Name>
  833. </ProjectReference>
  834. </ItemGroup>
  835. <ItemGroup>
  836. <Folder Include=""Properties\"" />
  837. </ItemGroup>
  838. <Import Project=""$(MSBuildToolsPath)\Microsoft.CSharp.targets"" />
  839. </Project>"},
  840. { "Program.cs",
  841. @"using System;
  842. using System.Collections.Generic;
  843. using System.Linq;
  844. using System.Text;
  845. using HelloLib;
  846. using VBLib;
  847. namespace HelloProj
  848. {
  849. class Program
  850. {
  851. static void Main(string[] args)
  852. {
  853. HelloLibClass.SayHello();
  854. VBLibClass.SayThere();
  855. Console.WriteLine(""World"");
  856. }
  857. }
  858. }
  859. "},
  860. { "HelloLib.csproj",
  861. @"<?xml version=""1.0"" encoding=""utf-8""?>
  862. <Project ToolsVersion=""4.0"" DefaultTargets=""Build"" xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
  863. <UsingTask TaskName=""Microsoft.CodeAnalysis.BuildTasks.Csc"" AssemblyFile=""" + BuildTaskDll + @""" />
  864. <PropertyGroup>
  865. <Configuration Condition="" '$(Configuration)' == '' "">Debug</Configuration>
  866. <Platform Condition="" '$(Platform)' == '' "">AnyCPU</Platform>
  867. <ProductVersion>8.0.30703</ProductVersion>
  868. <SchemaVersion>2.0</SchemaVersion>
  869. <ProjectGuid>{C1170A4A-80CF-4B4F-AA58-2FAEA9158D31}</ProjectGuid>
  870. <OutputType>Library</OutputType>
  871. <AppDesignerFolder>Properties</AppDesignerFolder>
  872. <RootNamespace>HelloLib</RootNamespace>
  873. <AssemblyName>HelloLib</AssemblyName>
  874. <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
  875. <FileAlignment>512</FileAlignment>
  876. </PropertyGroup>
  877. <PropertyGroup Condition="" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "">
  878. <DebugSymbols>true</DebugSymbols>
  879. <DebugType>full</DebugType>
  880. <Optimize>false</Optimize>
  881. <OutputPath>bin\Debug\</OutputPath>
  882. <DefineConstants>DEBUG;TRACE</DefineConstants>
  883. <ErrorReport>prompt</ErrorReport>
  884. <WarningLevel>4</WarningLevel>
  885. </PropertyGroup>
  886. <PropertyGroup Condition="" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "">
  887. <DebugType>pdbonly</DebugType>
  888. <Optimize>true</Optimize>
  889. <OutputPath>bin\Release\</OutputPath>
  890. <DefineConstants>TRACE</DefineConstants>
  891. <ErrorReport>prompt</ErrorReport>
  892. <WarningLevel>4</WarningLevel>
  893. </PropertyGroup>
  894. <ItemGroup>
  895. <Reference Include=""System"" />
  896. <Reference Include=""System.Core"" />
  897. <Reference Include=""System.Xml.Linq"" />
  898. <Reference Include=""System.Xml"" />
  899. </ItemGroup>
  900. <ItemGroup>
  901. <Compile Include=""HelloLib.cs"" />
  902. </ItemGroup>
  903. <ItemGroup>
  904. <Folder Include=""Properties\"" />
  905. </ItemGroup>
  906. <Import Project=""$(MSBuildToolsPath)\Microsoft.CSharp.targets"" />
  907. </Project>"},
  908. { "HelloLib.cs",
  909. @"using System;
  910. using System.Collections.Generic;
  911. using System.Linq;
  912. using System.Text;
  913. namespace HelloLib
  914. {
  915. public class HelloLibClass
  916. {
  917. public static void SayHello()
  918. {
  919. Console.WriteLine(""Hello"");
  920. }
  921. }
  922. }
  923. "},
  924. { "VBLib.vbproj",
  925. @"<?xml version=""1.0"" encoding=""utf-8""?>
  926. <Project ToolsVersion=""4.0"" DefaultTargets=""Build"" xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
  927. <UsingTask TaskName=""Microsoft.CodeAnalysis.BuildTasks.Vbc"" AssemblyFile=""" + BuildTaskDll + @""" />
  928. <PropertyGroup>
  929. <Configuration Condition="" '$(Configuration)' == '' "">Debug</Configuration>
  930. <Platform Condition="" '$(Platform)' == '' "">AnyCPU</Platform>
  931. <ProductVersion>
  932. </ProductVersion>
  933. <SchemaVersion>
  934. </SchemaVersion>
  935. <ProjectGuid>{F21C894B-28E5-4212-8AF7-C8E0E5455737}</ProjectGuid>
  936. <OutputType>Library</OutputType>
  937. <RootNamespace>VBLib</RootNamespace>
  938. <AssemblyName>VBLib</AssemblyName>
  939. <FileAlignment>512</FileAlignment>
  940. <MyType>Windows</MyType>
  941. <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
  942. </PropertyGroup>
  943. <PropertyGroup Condition="" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "">
  944. <DebugSymbols>true</DebugSymbols>
  945. <DebugType>full</DebugType>
  946. <DefineDebug>true</DefineDebug>
  947. <DefineTrace>true</DefineTrace>
  948. <OutputPath>bin\Debug\</OutputPath>
  949. <DocumentationFile>VBLib.xml</DocumentationFile>
  950. <NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
  951. </PropertyGroup>
  952. <PropertyGroup Condition="" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "">
  953. <DebugType>pdbonly</DebugType>
  954. <DefineDebug>false</DefineDebug>
  955. <DefineTrace>true</DefineTrace>
  956. <Optimize>true</Optimize>
  957. <OutputPath>bin\Release\</OutputPath>
  958. <DocumentationFile>VBLib.xml</DocumentationFile>
  959. <NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
  960. </PropertyGroup>
  961. <PropertyGroup>
  962. <OptionExplicit>On</OptionExplicit>
  963. </PropertyGroup>
  964. <PropertyGroup>
  965. <OptionCompare>Binary</OptionCompare>
  966. </PropertyGroup>
  967. <PropertyGroup>
  968. <OptionStrict>Off</OptionStrict>
  969. </PropertyGroup>
  970. <PropertyGroup>
  971. <OptionInfer>On</OptionInfer>
  972. </PropertyGroup>
  973. <ItemGroup>
  974. <Reference Include=""System"" />
  975. </ItemGroup>
  976. <ItemGroup>
  977. <Import Include=""Microsoft.VisualBasic"" />
  978. <Import Include=""System"" />
  979. <Import Include=""System.Collections.Generic"" />
  980. </ItemGroup>
  981. <ItemGroup>
  982. <Compile Include=""VBLib.vb"" />
  983. </ItemGroup>
  984. <Import Project=""$(MSBuildToolsPath)\Microsoft.VisualBasic.targets"" />
  985. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
  986. Other similar extension points exist, see Microsoft.Common.targets.
  987. -->
  988. </Project>"},
  989. { "VBLib.vb",
  990. @"
  991. Public Class VBLibClass
  992. Public Shared Sub SayThere()
  993. Console.WriteLine(""there"")
  994. End Sub
  995. End Class
  996. "}
  997. };
  998. }
  999. [Fact()]
  1000. public void SimpleMSBuild()
  1001. {
  1002. string arguments = string.Format(@"/m /nr:false /t:Rebuild /p:UseRoslyn=1 HelloSolution.sln");
  1003. var result = RunCommandLineCompiler(MSBuildExecutable, arguments, tempDirectory, GetSimpleMSBuildFiles());
  1004. using (var resultFile = GetResultFile(tempDirectory, @"bin\debug\helloproj.exe"))
  1005. {
  1006. // once we stop issuing BC40998 (NYI), we can start making stronger assertions
  1007. // about our ouptut in the general case
  1008. if (result.ExitCode != 0)
  1009. {
  1010. Assert.Equal("", result.Output);
  1011. Assert.Equal("", result.Errors);
  1012. }
  1013. Assert.Equal(0, result.ExitCode);
  1014. var runningResult = RunCompilerOutput(resultFile);
  1015. Assert.Equal("Hello\r\nthere\r\nWorld\r\n", runningResult.Output);
  1016. }
  1017. }
  1018. private Dictionary<string, string> GetMultiFileMSBuildFiles()
  1019. {
  1020. // Return a dictionary with name and contents of all the files we want to create for the SimpleMSBuild test.
  1021. return new Dictionary<string, string> {
  1022. {"ConsoleApplication1.sln",
  1023. @"
  1024. Microsoft Visual Studio Solution File, Format Version 12.00
  1025. # Visual Studio 2012
  1026. Project(""{F184B08F-C81C-45F6-A57F-5ABD9991F28F}"") = ""Mod1"", ""Mod1.vbproj"", ""{DEF6D929-FA03-4076-8A05-7BFA33DCC829}""
  1027. EndProject
  1028. Project(""{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"") = ""assem1"", ""assem1.csproj"", ""{1245560C-55E4-49D7-904C-18281B369763}""
  1029. EndProject
  1030. Project(""{F184B08F-C81C-45F6-A57F-5ABD9991F28F}"") = ""ConsoleApplication1"", ""ConsoleApplication1.vbproj"", ""{52F3466B-DD3F-435C-ADA6-CD023CC82E91}""
  1031. EndProject
  1032. Global
  1033. GlobalSection(SolutionConfigurationPlatforms) = preSolution
  1034. Debug|Any CPU = Debug|Any CPU
  1035. Release|Any CPU = Release|Any CPU
  1036. EndGlobalSection
  1037. GlobalSection(ProjectConfigurationPlatforms) = postSolution
  1038. {1245560C-55E4-49D7-904C-18281B369763}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
  1039. {1245560C-55E4-49D7-904C-18281B369763}.Debug|Any CPU.Build.0 = Debug|Any CPU
  1040. {1245560C-55E4-49D7-904C-18281B369763}.Release|Any CPU.ActiveCfg = Release|Any CPU
  1041. {1245560C-55E4-49D7-904C-18281B369763}.Release|Any CPU.Build.0 = Release|Any CPU
  1042. {52F3466B-DD3F-435C-ADA6-CD023CC82E91}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
  1043. {52F3466B-DD3F-435C-ADA6-CD023CC82E91}.Debug|Any CPU.Build.0 = Debug|Any CPU
  1044. {52F3466B-DD3F-435C-ADA6-CD023CC82E91}.Release|Any CPU.ActiveCfg = Release|Any CPU
  1045. {52F3466B-DD3F-435C-ADA6-CD023CC82E91}.Release|Any CPU.Build.0 = Release|Any CPU
  1046. {DEF6D929-FA03-4076-8A05-7BFA33DCC829}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
  1047. {DEF6D929-FA03-4076-8A05-7BFA33DCC829}.Debug|Any CPU.Build.0 = Debug|Any CPU
  1048. {DEF6D929-FA03-4076-8A05-7BFA33DCC829}.Release|Any CPU.ActiveCfg = Release|Any CPU
  1049. {DEF6D929-FA03-4076-8A05-7BFA33DCC829}.Release|Any CPU.Build.0 = Release|Any CPU
  1050. EndGlobalSection
  1051. GlobalSection(SolutionProperties) = preSolution
  1052. HideSolutionNode = FALSE
  1053. EndGlobalSection
  1054. EndGlobal
  1055. "},
  1056. {"ConsoleApplication1.vbproj",
  1057. @"<?xml version=""1.0"" encoding=""utf-8""?>
  1058. <Project ToolsVersion=""4.0"" DefaultTargets=""Build"" xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
  1059. <Import Project=""$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props"" Condition=""Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')"" />
  1060. <PropertyGroup>
  1061. <Configuration Condition="" '$(Configuration)' == '' "">Debug</Configuration>
  1062. <Platform Condition="" '$(Platform)' == '' "">AnyCPU</Platform>
  1063. <ProjectGuid>{52F3466B-DD3F-435C-ADA6-CD023CC82E91}</ProjectGuid>
  1064. <OutputType>Exe</OutputType>
  1065. <StartupObject>ConsoleApplication1.ConsoleApp</StartupObject>
  1066. <RootNamespace>ConsoleApplication1</RootNamespace>
  1067. <AssemblyName>ConsoleApplication1</AssemblyName>
  1068. <FileAlignment>512</FileAlignment>
  1069. <MyType>Console</MyType>
  1070. <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
  1071. </PropertyGroup>
  1072. <PropertyGroup Condition="" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "">
  1073. <PlatformTarget>AnyCPU</PlatformTarget>
  1074. <DebugSymbols>true</DebugSymbols>
  1075. <DebugType>full</DebugType>
  1076. <DefineDebug>true</DefineDebug>
  1077. <DefineTrace>true</DefineTrace>
  1078. <OutputPath>bin\Debug</OutputPath>
  1079. <DocumentationFile>ConsoleApplication1.xml</DocumentationFile>
  1080. <NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
  1081. </PropertyGroup>
  1082. <PropertyGroup>
  1083. <OptionExplicit>On</OptionExplicit>
  1084. </PropertyGroup>
  1085. <PropertyGroup>
  1086. <OptionCompare>Binary</OptionCompare>
  1087. </PropertyGroup>
  1088. <PropertyGroup>
  1089. <OptionStrict>Off</OptionStrict>
  1090. </PropertyGroup>
  1091. <PropertyGroup>
  1092. <OptionInfer>On</OptionInfer>
  1093. </PropertyGroup>
  1094. <ItemGroup>
  1095. <Import Include=""Microsoft.VisualBasic"" />
  1096. <Import Include=""System"" />
  1097. </ItemGroup>
  1098. <ItemGroup>
  1099. <Compile Include=""ConsoleApp.vb"" />
  1100. </ItemGroup>
  1101. <ItemGroup>
  1102. <Reference Include=""obj\debug\assem1.dll"">
  1103. </Reference>
  1104. </ItemGroup>
  1105. <Import Project=""$(MSBuildToolsPath)\Microsoft.VisualBasic.targets"" />
  1106. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
  1107. Other similar extension points exist, see Microsoft.Common.targets.
  1108. <Target Name=""BeforeBuild"">
  1109. </Target>
  1110. <Target Name=""AfterBuild"">
  1111. </Target>
  1112. -->
  1113. </Project>
  1114. "},
  1115. {"ConsoleApp.vb",
  1116. @"
  1117. Module ConsoleApp
  1118. Sub Main()
  1119. Console.WriteLine(""Hello"")
  1120. Console.WriteLine(AssemClass.GetNames())
  1121. Console.WriteLine(ModClass2.Name)
  1122. End Sub
  1123. End Module
  1124. "},
  1125. {"assem1.csproj",
  1126. @"<?xml version=""1.0"" encoding=""utf-8""?>
  1127. <Project ToolsVersion=""4.0"" DefaultTargets=""Build"" xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
  1128. <Import Project=""$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props"" Condition=""Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')"" />
  1129. <PropertyGroup>
  1130. <Configuration Condition="" '$(Configuration)' == '' "">Debug</Configuration>
  1131. <Platform Condition="" '$(Platform)' == '' "">AnyCPU</Platform>
  1132. <ProjectGuid>{1245560C-55E4-49D7-904C-18281B369763}</ProjectGuid>
  1133. <OutputType>Library</OutputType>
  1134. <AppDesignerFolder>Properties</AppDesignerFolder>
  1135. <RootNamespace>assem1</RootNamespace>
  1136. <AssemblyName>assem1</AssemblyName>
  1137. <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
  1138. <FileAlignment>512</FileAlignment>
  1139. </PropertyGroup>
  1140. <PropertyGroup Condition="" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "">
  1141. <DebugSymbols>true</DebugSymbols>
  1142. <DebugType>full</DebugType>
  1143. <Optimize>false</Optimize>
  1144. <OutputPath>bin\Debug\</OutputPath>
  1145. <DefineConstants>DEBUG;TRACE</DefineConstants>
  1146. <ErrorReport>prompt</ErrorReport>
  1147. <WarningLevel>4</WarningLevel>
  1148. </PropertyGroup>
  1149. <ItemGroup>
  1150. <Compile Include=""Assem1.cs"" />
  1151. </ItemGroup>
  1152. <ItemGroup>
  1153. <AddModules Include=""obj\Debug\Mod1.netmodule"">
  1154. </AddModules>
  1155. </ItemGroup>
  1156. <ItemGroup>
  1157. <Folder Include=""Properties\"" />
  1158. </ItemGroup>
  1159. <Import Project=""$(MSBuildToolsPath)\Microsoft.CSharp.targets"" />
  1160. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
  1161. Other similar extension points exist, see Microsoft.Common.targets.
  1162. <Target Name=""BeforeBuild"">
  1163. </Target>
  1164. <Target Name=""AfterBuild"">
  1165. </Target>
  1166. -->
  1167. </Project>
  1168. "},
  1169. {"Assem1.cs",
  1170. @"
  1171. using System;
  1172. using System.Collections.Generic;
  1173. using System.Linq;
  1174. using System.Text;
  1175. using System.Threading.Tasks;
  1176. public class AssemClass
  1177. {
  1178. public static string Name = ""AssemClass"";
  1179. public static string GetNames()
  1180. {
  1181. return Name + "" "" + ModClass.Name;
  1182. }
  1183. }
  1184. "},
  1185. {"Mod1.vbproj",
  1186. @"<?xml version=""1.0"" encoding=""utf-8""?>
  1187. <Project ToolsVersion=""4.0"" DefaultTargets=""Build"" xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
  1188. <Import Project=""$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props"" Condition=""Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')"" />
  1189. <PropertyGroup>
  1190. <Configuration Condition="" '$(Configuration)' == '' "">Debug</Configuration>
  1191. <Platform Condition="" '$(Platform)' == '' "">AnyCPU</Platform>
  1192. <ProjectGuid>{DEF6D929-FA03-4076-8A05-7BFA33DCC829}</ProjectGuid>
  1193. <OutputType>Module</OutputType>
  1194. <RootNamespace>
  1195. </RootNamespace>
  1196. <AssemblyName>Mod1</AssemblyName>
  1197. <FileAlignment>512</FileAlignment>
  1198. <MyType>Windows</MyType>
  1199. <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
  1200. </PropertyGroup>
  1201. <PropertyGroup Condition="" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "">
  1202. <DebugSymbols>true</DebugSymbols>
  1203. <DebugType>full</DebugType>
  1204. <DefineDebug>true</DefineDebug>
  1205. <DefineTrace>true</DefineTrace>
  1206. <OutputPath>bin\Debug\</OutputPath>
  1207. <DocumentationFile>Mod1.xml</DocumentationFile>
  1208. <NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
  1209. </PropertyGroup>
  1210. <PropertyGroup>
  1211. <OptionExplicit>On</OptionExplicit>
  1212. </PropertyGroup>
  1213. <PropertyGroup>
  1214. <OptionCompare>Binary</OptionCompare>
  1215. </PropertyGroup>
  1216. <PropertyGroup>
  1217. <OptionStrict>Off</OptionStrict>
  1218. </PropertyGroup>
  1219. <PropertyGroup>
  1220. <OptionInfer>On</OptionInfer>
  1221. </PropertyGroup>
  1222. <ItemGroup>
  1223. <Import Include=""Microsoft.VisualBasic"" />
  1224. <Import Include=""System"" />
  1225. </ItemGroup>
  1226. <ItemGroup>
  1227. <Compile Include=""Mod1.vb"" />
  1228. </ItemGroup>
  1229. <Import Project=""$(MSBuildToolsPath)\Microsoft.VisualBasic.targets"" />
  1230. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
  1231. Other similar extension points exist, see Microsoft.Common.targets.
  1232. <Target Name=""BeforeBuild"">
  1233. </Target>
  1234. <Target Name=""AfterBuild"">
  1235. </Target>
  1236. -->
  1237. </Project>
  1238. "},
  1239. {"Mod1.vb",
  1240. @"
  1241. Friend Class ModClass
  1242. Public Shared Name As String = ""ModClass""
  1243. End Class
  1244. Public Class ModClass2
  1245. Public Shared Name As String = ""ModClass2""
  1246. End Class
  1247. "}
  1248. };
  1249. }
  1250. [Fact]
  1251. [Trait(Traits.Environment, Traits.Environments.VSProductInstall)]
  1252. public void UseLibVariableCS()
  1253. {
  1254. var libDirectory = tempDirectory.CreateDirectory("LibraryDir");
  1255. // Create DLL "lib.dll"
  1256. Dictionary<string, string> files =
  1257. new Dictionary<string, string> {
  1258. { "src1.cs",
  1259. @"
  1260. public class Library
  1261. {
  1262. public static string GetString()
  1263. { return ""library1""; }
  1264. }"}};
  1265. var result = RunCommandLineCompiler(CSharpCompilerClientExecutable,
  1266. "src1.cs /nologo /t:library /out:" + libDirectory.Path + "\\lib.dll",
  1267. tempDirectory, files);
  1268. Assert.Equal("", result.Output);
  1269. Assert.Equal("", result.Errors);
  1270. Assert.Equal(0, result.ExitCode);
  1271. Temp.AddFile(GetResultFile(libDirectory, "lib.dll"));
  1272. // Create EXE "hello1.exe"
  1273. files = new Dictionary<string, string> {
  1274. { "hello1.cs",
  1275. @"using System;
  1276. class Hello
  1277. {
  1278. public static void Main()
  1279. { Console.WriteLine(""Hello1 from {0}"", Library.GetString()); }
  1280. }"}};
  1281. result = RunCommandLineCompiler(CSharpCompilerClientExecutable, "hello1.cs /nologo /r:lib.dll /out:hello1.exe", tempDirectory, files,
  1282. additionalEnvironmentVars: new Dictionary<string, string>() { { "LIB", libDirectory.Path } });
  1283. Assert.Equal("", result.Output);
  1284. Assert.Equal("", result.Errors);
  1285. Assert.Equal(0, result.ExitCode);
  1286. var resultFile = Temp.AddFile(GetResultFile(tempDirectory, "hello1.exe"));
  1287. }
  1288. [Fact]
  1289. [Trait(Traits.Environment, Traits.Environments.VSProductInstall)]
  1290. public void UseLibVariableVB()
  1291. {
  1292. var libDirectory = tempDirectory.CreateDirectory("LibraryDir");
  1293. // Create DLL "lib.dll"
  1294. Dictionary<string, string> files =
  1295. new Dictionary<string, string> {
  1296. { "src1.vb",
  1297. @"Imports System
  1298. Public Class Library
  1299. Public Shared Function GetString() As String
  1300. Return ""library1""
  1301. End Function
  1302. End Class
  1303. "}};
  1304. var result = RunCommandLineCompiler(BasicCompilerClientExecutable,
  1305. "src1.vb /nologo /t:library /out:" + libDirectory.Path + "\\lib.dll",
  1306. tempDirectory, files);
  1307. Assert.Equal("", result.Output);
  1308. Assert.Equal("", result.Errors);
  1309. Assert.Equal(0, result.ExitCode);
  1310. Temp.AddFile(GetResultFile(libDirectory, "lib.dll"));
  1311. // Create EXE "hello1.exe"
  1312. files = new Dictionary<string, string> {
  1313. { "hello1.vb",
  1314. @"Imports System
  1315. Module Module1
  1316. Public Sub Main()
  1317. Console.WriteLine(""Hello1 from {0}"", Library.GetString())
  1318. End Sub
  1319. End Module
  1320. "}};
  1321. result = RunCommandLineCompiler(BasicCompilerClientExecutable, "hello1.vb /nologo /r:Microsoft.VisualBasic.dll /r:lib.dll /out:hello1.exe", tempDirectory, files,
  1322. additionalEnvironmentVars: new Dictionary<string, string>() { { "LIB", libDirectory.Path } });
  1323. Assert.Equal("", result.Output);
  1324. Assert.Equal("", result.Errors);
  1325. Assert.Equal(0, result.ExitCode);
  1326. var resultFile = Temp.AddFile(GetResultFile(tempDirectory, "hello1.exe"));
  1327. }
  1328. [WorkItem(545446, "DevDiv")]
  1329. [Fact()]
  1330. [Trait(Traits.Environment, Traits.Environments.VSProductInstall)]
  1331. public void Utf8Output_WithRedirecting_Off_csc2()
  1332. {
  1333. var srcFile = tempDirectory.CreateFile("test.cs").WriteAllText("♕").Path;
  1334. var tempOut = tempDirectory.CreateFile("output.txt");
  1335. var result = ProcessLauncher.Run("cmd", string.Format("/C csc2.exe /nologo /t:library {0} > {1}", srcFile, tempOut.Path));
  1336. Assert.Equal("", result.Output.Trim());
  1337. Assert.Equal("SRC.CS(1,1): error CS1056: Unexpected character '?'".Trim(),
  1338. tempOut.ReadAllText().Trim().Replace(srcFile, "SRC.CS"));
  1339. Assert.Equal(1, result.ExitCode);
  1340. }
  1341. [WorkItem(545446, "DevDiv")]
  1342. [Fact()]
  1343. [Trait(Traits.Environment, Traits.Environments.VSProductInstall)]
  1344. public void Utf8Output_WithRedirecting_Off_vbc2()
  1345. {
  1346. var srcFile = tempDirectory.CreateFile("test.vb").WriteAllText(@"♕").Path;
  1347. var tempOut = tempDirectory.CreateFile("output.txt");
  1348. var result = ProcessLauncher.Run("cmd", string.Format("/C vbc2.exe /nologo /t:library {0} > {1}", srcFile, tempOut.Path));
  1349. Assert.Equal("", result.Output.Trim());
  1350. Assert.Equal(@"SRC.VB(1) : error BC30037: Character is not valid.
  1351. ?
  1352. ~
  1353. ".Trim(),
  1354. tempOut.ReadAllText().Trim().Replace(srcFile, "SRC.VB"));
  1355. Assert.Equal(1, result.ExitCode);
  1356. }
  1357. [WorkItem(545446, "DevDiv")]
  1358. [Fact()]
  1359. [Trait(Traits.Environment, Traits.Environments.VSProductInstall)]
  1360. public void Utf8Output_WithRedirecting_On_csc2()
  1361. {
  1362. var srcFile = tempDirectory.CreateFile("test.cs").WriteAllText("♕").Path;
  1363. var tempOut = tempDirectory.CreateFile("output.txt");
  1364. var result = ProcessLauncher.Run("cmd", string.Format("/C csc2.exe /utf8output /nologo /t:library {0} > {1}", srcFile, tempOut.Path));
  1365. Assert.Equal("", result.Output.Trim());
  1366. Assert.Equal("SRC.CS(1,1): error CS1056: Unexpected character '♕'".Trim(),
  1367. tempOut.ReadAllText().Trim().Replace(srcFile, "SRC.CS"));
  1368. Assert.Equal(1, result.ExitCode);
  1369. }
  1370. [WorkItem(545446, "DevDiv")]
  1371. [Fact()]
  1372. [Trait(Traits.Environment, Traits.Environments.VSProductInstall)]
  1373. public void Utf8Output_WithRedirecting_On_vbc2()
  1374. {
  1375. var srcFile = tempDirectory.CreateFile("test.vb").WriteAllText(@"♕").Path;
  1376. var tempOut = tempDirectory.CreateFile("output.txt");
  1377. var result = ProcessLauncher.Run("cmd", string.Format("/C vbc2.exe /utf8output /nologo /t:library {0} > {1}", srcFile, tempOut.Path));
  1378. Assert.Equal("", result.Output.Trim());
  1379. Assert.Equal(@"SRC.VB(1) : error BC30037: Character is not valid.
  1380. ~
  1381. ".Trim(),
  1382. tempOut.ReadAllText().Trim().Replace(srcFile, "SRC.VB"));
  1383. Assert.Equal(1, result.ExitCode);
  1384. }
  1385. [WorkItem(871477, "DevDiv")]
  1386. [Fact]
  1387. [Trait(Traits.Environment, Traits.Environments.VSProductInstall)]
  1388. public void AssemblyIdentityComparer1()
  1389. {
  1390. tempDirectory.CreateFile("mscorlib20.dll").WriteAllBytes(ProprietaryTestResources.NetFX.v2_0_50727.mscorlib);
  1391. tempDirectory.CreateFile("mscorlib40.dll").WriteAllBytes(ProprietaryTestResources.NetFX.v4_0_21006.mscorlib);
  1392. // Create DLL "lib.dll"
  1393. Dictionary<string, string> files =
  1394. new Dictionary<string, string> {
  1395. { "ref_mscorlib2.cs",
  1396. @"public class C
  1397. {
  1398. public System.Exception GetException()
  1399. {
  1400. return null;
  1401. }
  1402. }
  1403. "}};
  1404. var result = RunCommandLineCompiler(CSharpCompilerClientExecutable,
  1405. "ref_mscorlib2.cs /nologo /nostdlib /noconfig /t:library /r:mscorlib20.dll",
  1406. tempDirectory, files);
  1407. Assert.Equal("", result.Output);
  1408. Assert.Equal("", result.Errors);
  1409. Assert.Equal(0, result.ExitCode);
  1410. Temp.AddFile(GetResultFile(tempDirectory, "ref_mscorlib2.dll"));
  1411. // Create EXE "main.exe"
  1412. files = new Dictionary<string, string> {
  1413. { "main.cs",
  1414. @"using System;
  1415. class Program
  1416. {
  1417. static void Main(string[] args)
  1418. {
  1419. var e = new C().GetException();
  1420. Console.WriteLine(e);
  1421. }
  1422. }
  1423. "}};
  1424. result = RunCommandLineCompiler(CSharpCompilerClientExecutable,
  1425. "main.cs /nologo /nostdlib /noconfig /r:mscorlib40.dll /r:ref_mscorlib2.dll",
  1426. tempDirectory, files);
  1427. Assert.Equal("", result.Output);
  1428. Assert.Equal("", result.Errors);
  1429. Assert.Equal(0, result.ExitCode);
  1430. }
  1431. }
  1432. }