public void VbcHostObject() { IBuildEngine2 mockEngine = new MockEngine(); Vbc vbc = new Vbc(); vbc.BuildEngine = mockEngine; MockVbcHostObject vbcHostObject = new MockVbcHostObject5(); vbc.HostObject = vbcHostObject; vbc.UseHostCompilerIfAvailable = true; Assert.IsTrue(!vbcHostObject.CompileMethodWasCalled); vbc.Sources = new TaskItem[] { new TaskItem("a.vb") }; bool vbcSuccess = vbc.Execute(); Assert.IsTrue(vbcSuccess, "Vbc task failed."); Assert.IsTrue(vbcHostObject.CompileMethodWasCalled); }
public void NoAdditionalFile_HostObject() { IBuildEngine2 mockEngine = new MockEngine(); Vbc vbc = new Vbc(); vbc.BuildEngine = mockEngine; MockVbcAnalyzerHostObject vbcHostObject = new MockVbcAnalyzerHostObject(); vbcHostObject.SetDesignTime(true); vbc.HostObject = vbcHostObject; vbc.UseHostCompilerIfAvailable = true; Assert.IsNull(vbcHostObject.AdditionalFiles); vbc.Sources = new TaskItem[] { new TaskItem("a.cs") }; bool vbcSuccess = vbc.Execute(); Assert.IsTrue(vbcSuccess, "Vbc task failed."); Assert.IsNull(vbcHostObject.AdditionalFiles); }
public void MultipleAdditionalFiles_HostObject() { IBuildEngine2 mockEngine = new MockEngine(); Vbc vbc = new Vbc(); vbc.BuildEngine = mockEngine; MockVbcAnalyzerHostObject vbcHostObject = new MockVbcAnalyzerHostObject(); vbcHostObject.SetDesignTime(true); vbc.HostObject = vbcHostObject; vbc.UseHostCompilerIfAvailable = true; Assert.IsNull(vbcHostObject.AdditionalFiles); vbc.AdditionalFiles = new TaskItem[] { new TaskItem("web.config"), new TaskItem("app.config") }; vbc.Sources = new TaskItem[] { new TaskItem("a.cs") }; bool vbcSuccess = vbc.Execute(); Assert.IsTrue(vbcSuccess, "Vbc task failed."); Assert.AreEqual(2, vbcHostObject.AdditionalFiles.Length); Assert.AreEqual("web.config", vbcHostObject.AdditionalFiles[0].ItemSpec); Assert.AreEqual("app.config", vbcHostObject.AdditionalFiles[1].ItemSpec); }
public void RuleSet_HostObject() { IBuildEngine2 mockEngine = new MockEngine(); Vbc vbc = new Vbc(); vbc.BuildEngine = mockEngine; MockVbcAnalyzerHostObject vbcHostObject = new MockVbcAnalyzerHostObject(); vbcHostObject.SetDesignTime(true); vbc.HostObject = vbcHostObject; vbc.UseHostCompilerIfAvailable = true; Assert.IsNull(vbcHostObject.RuleSet); vbc.CodeAnalysisRuleSet = "Bar.ruleset"; vbc.Sources = new TaskItem[] { new TaskItem("a.vb") }; bool vbcSuccess = vbc.Execute(); Assert.IsTrue(vbcSuccess, "Vbc task failed."); Assert.AreEqual("Bar.ruleset", vbcHostObject.RuleSet); }
public void Analyzer_HostObject() { IBuildEngine2 mockEngine = new MockEngine(); Vbc vbc = new Vbc(); vbc.BuildEngine = mockEngine; MockVbcAnalyzerHostObject vbcHostObject = new MockVbcAnalyzerHostObject(); vbcHostObject.SetDesignTime(true); vbc.HostObject = vbcHostObject; vbc.UseHostCompilerIfAvailable = true; Assert.IsNull(vbcHostObject.Analyzers); vbc.Analyzers = new TaskItem[] { new TaskItem("Foo.dll") }; vbc.Sources = new TaskItem[] { new TaskItem("a.vb") }; bool vbcSuccess = vbc.Execute(); Assert.IsTrue(vbcSuccess, "Vbc task failed."); Assert.AreEqual(1, vbcHostObject.Analyzers.Length); Assert.AreEqual("Foo.dll", vbcHostObject.Analyzers[0].ItemSpec); }
/// <summary> /// Invokes VBC to build the given files against the given set of references /// </summary> /// <param name="files"></param> /// <param name="referenceAssemblies"></param> public static bool CompileVisualBasicSource(IEnumerable<string> files, IEnumerable<string> referenceAssemblies, string rootNamespace) { List<ITaskItem> sources = new List<ITaskItem>(); foreach (string f in files) sources.Add(new TaskItem(f)); List<ITaskItem> references = new List<ITaskItem>(); foreach (string s in referenceAssemblies) { // VB cannot accept mscorlib in the references if (s.IndexOf("mscorlib", StringComparison.OrdinalIgnoreCase) < 0) { references.Add(new TaskItem(s)); } } Vbc vbc = new Vbc(); MockBuildEngine buildEngine = new MockBuildEngine(); vbc.BuildEngine = buildEngine; // needed before task can log vbc.NoStandardLib = true; // don't include std lib stuff -- we're feeding it silverlight vbc.NoConfig = true; // don't load the vbc.rsp file to get references vbc.TargetType = "library"; vbc.Sources = sources.ToArray(); vbc.References = references.ToArray(); //$$$ vbc.SdkPath = GetSilverlightPath(); vbc.RootNamespace = rootNamespace; bool result = false; try { result = vbc.Execute(); } catch (Exception ex) { Assert.Fail("Exception occurred invoking VBC task on " + sources[0].ItemSpec + ":\r\n" + ex); } if (!result) { string sourceList = string.Empty; foreach (TaskItem t in sources) { sourceList += " " + t.ItemSpec + "\r\n"; } Assert.Fail("VBC failed to compile sources:\r\n" + sourceList + "\r\n" + buildEngine.ConsoleLogger.Errors + "\r\n\r\nReference assemblies were:\r\n" + ReferenceAssembliesAsString(referenceAssemblies)); } return result; }
/// <summary> /// Invokes VBC to build the given files against the given set of references /// </summary> /// <param name="files"></param> /// <param name="referenceAssemblies"></param> /// <param name="documentationFile">If nonblank, the documentation file to generate during the compile.</param> public static bool CompileVisualBasicSource(IEnumerable<string> files, IEnumerable<string> referenceAssemblies, string rootNamespace, string documentationFile) { List<ITaskItem> sources = new List<ITaskItem>(); foreach (string f in files) sources.Add(new TaskItem(f)); // Transform references into a list of ITaskItems. // Here, we skip over mscorlib explicitly because this is already included as a project reference. List<ITaskItem> references = referenceAssemblies .Where(reference => !reference.EndsWith("mscorlib.dll", StringComparison.Ordinal)) .Select<string, ITaskItem>(reference => new TaskItem(reference) as ITaskItem) .ToList(); Vbc vbc = new Vbc(); MockBuildEngine buildEngine = new MockBuildEngine(); vbc.BuildEngine = buildEngine; // needed before task can log vbc.NoStandardLib = true; // don't include std lib stuff -- we're feeding it silverlight vbc.NoConfig = true; // don't load the vbc.rsp file to get references vbc.TargetType = "library"; vbc.Sources = sources.ToArray(); vbc.References = references.ToArray(); vbc.SdkPath = GetSilverlightSdkReferenceAssembliesPath(); vbc.DefineConstants += "SILVERLIGHT"; if (!string.IsNullOrEmpty(rootNamespace)) { vbc.RootNamespace = rootNamespace; } if (!string.IsNullOrEmpty(documentationFile)) { vbc.DocumentationFile = documentationFile; } bool result = false; try { result = vbc.Execute(); } catch (Exception ex) { Assert.Fail("Exception occurred invoking VBC task on " + sources[0].ItemSpec + ":\r\n" + ex); } Assert.IsTrue(result, "VBC failed to compile " + sources[0].ItemSpec + ":\r\n" + buildEngine.ConsoleLogger.Errors); return result; }
internal string CompileVisualBasicSource() { List<ITaskItem> sources = new List<ITaskItem>(); sources.Add(new TaskItem(this.GeneratedCodeFile)); // If client has added extra user code into the // compile request, add it in now string userCodeFile = this.UserCodeFile; if (!string.IsNullOrEmpty(userCodeFile)) { sources.Add(new TaskItem(userCodeFile)); } // Transform references into a list of ITaskItems. // Here, we skip over mscorlib explicitly because this is already included as a project reference. List<ITaskItem> references = this.ReferenceAssemblies .Where(reference => !reference.EndsWith("mscorlib.dll", StringComparison.Ordinal)) .Select<string, ITaskItem>(reference => new TaskItem(reference) as ITaskItem) .ToList(); Vbc vbc = new Vbc(); MockBuildEngine buildEngine = this.MockBuildEngine; vbc.BuildEngine = buildEngine; // needed before task can log vbc.NoStandardLib = true; // don't include std lib stuff -- we're feeding it silverlight vbc.NoConfig = true; // don't load the vbc.rsp file to get references vbc.TargetType = "library"; vbc.Sources = sources.ToArray(); vbc.References = references.ToArray(); vbc.SdkPath = CompilerHelper.GetSilverlightSdkReferenceAssembliesPath(); vbc.RootNamespace = "TestRootNS"; vbc.DefineConstants += "SILVERLIGHT"; vbc.OutputAssembly = new TaskItem(this.OutputAssemblyName); bool result = false; try { result = vbc.Execute(); } catch (Exception ex) { Assert.Fail("Exception occurred invoking VBC task on " + sources[0].ItemSpec + ":\r\n" + ex); } Assert.IsTrue(result, "VBC failed to compile " + sources[0].ItemSpec + ":\r\n" + buildEngine.ConsoleLogger.Errors); return vbc.OutputAssembly.ItemSpec; }