Beispiel #1
0
        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);
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        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);
        }
Beispiel #4
0
        /// <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);
        }
Beispiel #5
0
        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);
        }
Beispiel #6
0
        /// <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)
        {
            var 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(reference => new TaskItem(reference) as ITaskItem)
                .ToList();

            var buildEngine = new MockBuildEngine();
            var vbc         = new Vbc();

            vbc.BuildEngine = buildEngine; // needed before task can log

            vbc.NoStandardLib = true;      // don't include std lib stuff -- we're feeding it pcl
            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 = GetSdkReferenceAssembliesPath();

            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);
        }
Beispiel #7
0
        internal string CompileVisualBasicSource()
        {
            var sources = new List <ITaskItem>();

            sources.Add(new TaskItem(GeneratedCodeFile));

            // If client has added extra user code into the
            // compile request, add it in now
            string userCodeFile = 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.
            var references = ReferenceAssemblies
                             .Where(reference => !reference.EndsWith("mscorlib.dll", StringComparison.Ordinal))
                             .Select(reference => new TaskItem(reference) as ITaskItem)
                             .ToList();

            var buildEngine = MockBuildEngine;
            var vbc         = new Vbc
            {
                BuildEngine    = buildEngine,
                NoStandardLib  = true,
                NoConfig       = true,
                TargetType     = "library",
                Sources        = sources.ToArray(),
                References     = references.ToArray(),
                RootNamespace  = "TestRootNS",
                OutputAssembly = new TaskItem(OutputAssemblyName)
            };

            //vbc.SdkPath = @"C:\Windows\Microsoft.NET\Framework\v4.0.30319\";

            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);
        }
Beispiel #8
0
        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);
        }
Beispiel #9
0
        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);
        }
Beispiel #10
0
        public void ExecuteVbcBuildTaskWithServer()
        {
            var vbc = new Vbc();
            var srcFile = _tempDirectory.CreateFile(s_helloWorldSrcVb[0].Key).WriteAllText(s_helloWorldSrcVb[0].Value).Path;
            var exeFile = Path.Combine(_tempDirectory.Path, "hello.exe");

            var engine = new MockEngine();
            vbc.BuildEngine = engine;
            vbc.Sources = new[] { new Build.Utilities.TaskItem(srcFile) };
            vbc.NoLogo = true;
            vbc.OutputAssembly = new Build.Utilities.TaskItem(exeFile);
            vbc.ToolPath = "";
            vbc.ToolExe = "";
            vbc.UseSharedCompilation = true;

            vbc.Execute();

            Assert.Equal(0, vbc.ExitCode);
            Assert.Equal(string.Empty, engine.Warnings);
            Assert.Equal(string.Empty, engine.Errors);

            Assert.True(File.Exists(exeFile));

            var result = ProcessUtilities.Run(exeFile, "");
            Assert.Equal(0, result.ExitCode);
            Assert.Equal("Hello from VB", result.Output.Trim());
        }