public void ResgenCommandLineLogging() { // This WriteLine is a hack. On a slow machine, the Tasks unittest fails because remoting // times out the object used for remoting console writes. Adding a write in the middle of // keeps remoting from timing out the object. Console.WriteLine("Performing ResgenCommandLineLogging() test"); // we use this to check if paths need quoting CommandLineBuilderHelper commandLineBuilderHelper = new CommandLineBuilderHelper(); string resxFile = Utilities.WriteTestResX(false, null, null); string resourcesFile = Path.ChangeExtension(resxFile, ".resources"); File.Delete(resourcesFile); try { GenerateResource t = Utilities.CreateTask(); t.Sources = new ITaskItem[] { new TaskItem(resxFile) }; t.UseSourcePath = false; t.NeverLockTypeAssemblies = false; t.Execute(); string possiblyQuotedResxFile = resxFile; string possiblyQuotedResourcesFile = resourcesFile; if (commandLineBuilderHelper.DoesPathNeedQuotes(resxFile)) { possiblyQuotedResxFile = "\"" + resxFile + "\""; } if (commandLineBuilderHelper.DoesPathNeedQuotes(resourcesFile)) { possiblyQuotedResourcesFile = "\"" + resourcesFile + "\""; } Utilities.AssertLogContains(t, " /compile " + possiblyQuotedResxFile + "," + possiblyQuotedResourcesFile); } finally { File.Delete(resxFile); File.Delete(resourcesFile); } resxFile = Utilities.WriteTestResX(false, null, null); resourcesFile = Path.ChangeExtension(resxFile, ".resources"); File.Delete(resourcesFile); try { GenerateResource t = Utilities.CreateTask(); t.Sources = new ITaskItem[] { new TaskItem(resxFile) }; t.References = new ITaskItem[] { new TaskItem("baz"), new TaskItem("jazz") }; t.UseSourcePath = true; t.PublicClass = true; t.StronglyTypedLanguage = "C#"; t.NeverLockTypeAssemblies = false; t.Execute(); string possiblyQuotedResxFile = resxFile; string possiblyQuotedResourcesFile = resourcesFile; if (commandLineBuilderHelper.DoesPathNeedQuotes(resxFile)) { possiblyQuotedResxFile = "\"" + resxFile + "\""; } if (commandLineBuilderHelper.DoesPathNeedQuotes(resourcesFile)) { possiblyQuotedResourcesFile = "\"" + resourcesFile + "\""; } Utilities.AssertLogContains(t, " /useSourcePath /publicClass /r:baz /r:jazz " + possiblyQuotedResxFile + " " + possiblyQuotedResourcesFile + " /str:\"C#\",,,"); } finally { File.Delete(resxFile); File.Delete(resourcesFile); File.Delete(Path.ChangeExtension(resxFile, ".cs")); } resxFile = Utilities.WriteTestResX(false, null, null); resourcesFile = Path.ChangeExtension(resxFile, ".resources"); File.Delete(resourcesFile); try { GenerateResource t = Utilities.CreateTask(); t.Sources = new ITaskItem[] { new TaskItem(resxFile) }; t.References = new ITaskItem[] { new TaskItem("baz"), new TaskItem("jazz") }; t.UseSourcePath = true; t.StronglyTypedLanguage = "C#"; t.StronglyTypedClassName = "wagwag"; t.StronglyTypedFileName = "boo"; t.NeverLockTypeAssemblies = false; t.Execute(); string possiblyQuotedResxFile = resxFile; string possiblyQuotedResourcesFile = resourcesFile; if (commandLineBuilderHelper.DoesPathNeedQuotes(resxFile)) { possiblyQuotedResxFile = "\"" + resxFile + "\""; } if (commandLineBuilderHelper.DoesPathNeedQuotes(resourcesFile)) { possiblyQuotedResourcesFile = "\"" + resourcesFile + "\""; } Utilities.AssertLogContains(t, " /useSourcePath /r:baz /r:jazz " + possiblyQuotedResxFile + " " + possiblyQuotedResourcesFile + " /str:\"C#\",,wagwag,boo"); } finally { File.Delete(resxFile); File.Delete(resourcesFile); } resxFile = Utilities.WriteTestResX(false, null, null); resourcesFile = Path.ChangeExtension(resxFile, ".myresources"); File.Delete(resourcesFile); string resxFile1 = Utilities.WriteTestResX(false, null, null); string resourcesFile1 = Path.ChangeExtension(resxFile1, ".myresources"); File.Delete(resourcesFile1); try { GenerateResource t = Utilities.CreateTask(); t.Sources = new ITaskItem[] { new TaskItem(resxFile), new TaskItem(resxFile1) }; t.OutputResources = new ITaskItem[] { new TaskItem(resourcesFile), new TaskItem(resourcesFile1) }; t.NeverLockTypeAssemblies = false; t.Execute(); string possiblyQuotedResxFile = resxFile; string possiblyQuotedResourcesFile = resourcesFile; string possiblyQuotedResxFile1 = resxFile1; string possiblyQuotedResourcesFile1 = resourcesFile1; if (commandLineBuilderHelper.DoesPathNeedQuotes(resxFile)) { possiblyQuotedResxFile = "\"" + resxFile + "\""; } if (commandLineBuilderHelper.DoesPathNeedQuotes(resourcesFile)) { possiblyQuotedResourcesFile = "\"" + resourcesFile + "\""; } if (commandLineBuilderHelper.DoesPathNeedQuotes(resxFile1)) { possiblyQuotedResxFile1 = "\"" + resxFile1 + "\""; } if (commandLineBuilderHelper.DoesPathNeedQuotes(resourcesFile1)) { possiblyQuotedResourcesFile1 = "\"" + resourcesFile1 + "\""; } Utilities.AssertLogContains(t, " /compile " + possiblyQuotedResxFile + "," + possiblyQuotedResourcesFile + " " + possiblyQuotedResxFile1 + "," + possiblyQuotedResourcesFile1); } finally { File.Delete(resxFile); File.Delete(resourcesFile); File.Delete(resxFile1); File.Delete(resourcesFile1); } }
public void ResgenCommandLineExceedsAllowedLength() { string sdkToolsPath; string net35 = ToolLocationHelper.GetPathToDotNetFramework(TargetDotNetFrameworkVersion.Version35); string net35sdk = ToolLocationHelper.GetPathToDotNetFrameworkSdk(TargetDotNetFrameworkVersion.Version35, VisualStudioVersion.VersionLatest); // If .NET 3.5 isn't installed, then the ToolLocationHelper will either return null or there won't be an MSBuild subfolder under the Framework directory for .NET 3.5 if (net35 != null && Directory.Exists(Path.Combine(net35, "MSBuild")) && net35sdk != null && Directory.Exists(Path.Combine(net35sdk, "bin"))) { sdkToolsPath = Path.Combine(net35sdk, "bin"); } else { Assert.IsTrue(true, "We only need to test .NET 3.5 ResGen, if it isn't on disk then pass the test and return"); return; } // This WriteLine is a hack. On a slow machine, the Tasks unittest fails because remoting // times out the object used for remoting console writes. Adding a write in the middle of // keeps remoting from timing out the object. Console.WriteLine("Performing ResgenCommandLineExceedsAllowedLength() test"); // we use this to check if paths need quoting CommandLineBuilderHelper commandLineBuilderHelper = new CommandLineBuilderHelper(); List<ITaskItem> sources = new List<ITaskItem>(); List<ITaskItem> outputResources = new List<ITaskItem>(); try { int filesToBeCreated = 83; // The filesToBeCreated number is determined from the Username length and the given explicitly set temp folder. // These numbers were shown through trial and error to be the correct numbers. switch (Environment.UserName.Length) { case 1: case 2: filesToBeCreated = 89; break; case 3: case 4: case 5: filesToBeCreated = 88; break; case 6: case 7: case 8: case 9: filesToBeCreated = 87; break; case 10: case 11: case 12: case 13: filesToBeCreated = 86; break; case 14: case 15: case 16: case 17: filesToBeCreated = 85; break; case 18: case 19: case 20: filesToBeCreated = 84; break; } // Get the generic "Temp" folder from the users' LocalAppData path in case they specify a different "Temp" folder or it's // located on a drive other than C. string tempFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "temp"); // This loop creates "filesToBeCreated" source files (+ output files) of 140 characters each such that the last one exceeds // the 28,000 command line max length limit in order to validate that resgen is behaving properly in that scenario for (int x = 0; x < filesToBeCreated; x++) { string fileName = new String('c', 133) + String.Format("{0:00}", x); string resxFile = MyResxFileCreator(tempFolder, fileName); string resourcesFile = Path.ChangeExtension(fileName, ".resources"); sources.Add(new TaskItem(resxFile)); outputResources.Add(new TaskItem(resourcesFile)); File.Delete(resourcesFile); } GenerateResource t = Utilities.CreateTaskOutOfProc(); t.Sources = sources.ToArray(); t.OutputResources = outputResources.ToArray(); t.StronglyTypedLanguage = null; t.UseSourcePath = false; t.NeverLockTypeAssemblies = false; t.SdkToolsPath = sdkToolsPath; Assert.IsTrue(t.Execute(), "Task should have completed succesfully"); Utilities.AssertLogContains(t, "/compile"); foreach (ITaskItem i in sources) { Utilities.AssertLogContains(t, i.ItemSpec); } foreach (ITaskItem i in outputResources) { Utilities.AssertLogContains(t, i.ItemSpec); } } finally { foreach (ITaskItem i in sources) { File.Delete(i.ItemSpec); } foreach (ITaskItem i in outputResources) { File.Delete(i.ItemSpec); } } }