Inheritance: Microsoft.Build.Tasks.ManagedCompiler
Exemplo n.º 1
0
        public void References()
        {
            Vbc t = new Vbc();

            TaskItem reference = new TaskItem("System.Xml.dll");
            reference.SetMetadata("Alias", "Foo");

            t.References = new TaskItem[] { reference };
            CommandLine.ValidateHasParameter(t, "/reference:System.Xml.dll");
        }
        /// <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;
        }
Exemplo n.º 4
0
 public void BaseAddressDecimal()
 {
     Vbc t = new Vbc();
     t.BaseAddress = "285212672";
     CommandLine.ValidateHasParameter(t, "/baseaddress:11000000");
 }
Exemplo n.º 5
0
        public void MovePDBFile_BadFileName()
        {
            string tempDirectory = Path.Combine(Path.GetTempPath(), "MovePDBFile_BadFileName");

            try
            {
                if (Directory.Exists(tempDirectory))
                {
                    FileUtilities.DeleteDirectoryNoThrow(tempDirectory, true);
                }

                Directory.CreateDirectory(tempDirectory);

                string outputAssemblyPath = Path.Combine(tempDirectory, "Out.dll");
                string outputPDBPath = Path.Combine(tempDirectory, "Out.pdb");
                File.WriteAllText(outputPDBPath, "Hello");
                File.WriteAllText(outputAssemblyPath, "Hello");

                MockEngine engine = new MockEngine();
                Vbc t = new Vbc();
                t.BuildEngine = engine;
                t.PdbFile = "||{}}{<>?$$%^&*()!@#$%`~.pdb";
                t.MovePdbFileIfNecessary(outputAssemblyPath);

                FileInfo oldPDBInfo = new FileInfo(outputAssemblyPath);
                Assert.IsTrue(oldPDBInfo.Exists);

                Assert.IsTrue(engine.Errors >= 1, "Should be one error");
                (t.BuildEngine as MockEngine).AssertLogContains("MSB3402");
            }
            finally
            {
                if (Directory.Exists(tempDirectory))
                {
                    FileUtilities.DeleteDirectoryNoThrow(tempDirectory, true);
                }
            }
        }
Exemplo n.º 6
0
 public void BaseAddressHex4()
 {
     Vbc t = new Vbc();
     t.BaseAddress = "0X00001000";
     CommandLine.ValidateHasParameter(t, "/baseaddress:00001000");
 }
Exemplo n.º 7
0
        public void ParseError_StandardVbcErrorFollowedByProjectLevel()
        {
            Vbc t = new Vbc();
            t.BuildEngine = new MockEngine();

            string error1 = "d:\\scratch\\607654\\Module1.vb(5) : error BC30800: Method arguments must be enclosed in parentheses : Don't you think?";
            string error2 = "";
            string error3 = "    Ed Sub";
            string error4 = "       ~~~";

            string error5 = "vbc : error BC30573: Error in project-level import '<xmlns=\"hi\">' at '<xmlns=\"hi\">' : XML namespace prefix '' is already declared";

            t.ParseVBErrorOrWarning(error1, MessageImportance.High);
            t.ParseVBErrorOrWarning(error2, MessageImportance.High);
            t.ParseVBErrorOrWarning(error3, MessageImportance.High);
            t.ParseVBErrorOrWarning(error4, MessageImportance.High);
            t.ParseVBErrorOrWarning(error5, MessageImportance.High);

            Assert.IsTrue((t.BuildEngine as MockEngine).Errors >= 2, "Should be at least two errors");
            (t.BuildEngine as MockEngine).AssertLogContains("BC30573");
            (t.BuildEngine as MockEngine).AssertLogContains("BC30800");
        }
Exemplo n.º 8
0
 public void BaseAddressHex3()
 {
     Vbc t = new Vbc();
     t.BaseAddress = "0x0000FFFF";
     CommandLine.ValidateHasParameter(t, "/baseaddress:0000FFFF");
 }
Exemplo n.º 9
0
        public void ParseError_StandardVbcError()
        {
            Vbc t = new Vbc();
            t.BuildEngine = new MockEngine();

            string error1 = "d:\\scratch\\607654\\Module1.vb(5) : error BC30451: Name 'Ed' is not declared.";
            string error2 = "";
            string error3 = "    Ed Sub";
            string error4 = "    ~~    ";

            t.ParseVBErrorOrWarning(error1, MessageImportance.High);
            t.ParseVBErrorOrWarning(error2, MessageImportance.High);
            t.ParseVBErrorOrWarning(error3, MessageImportance.High);
            t.ParseVBErrorOrWarning(error4, MessageImportance.High);

            Assert.IsTrue((t.BuildEngine as MockEngine).Errors >= 1, "Should be at least one error");
            (t.BuildEngine as MockEngine).AssertLogContains("BC30451");
            (t.BuildEngine as MockEngine).AssertLogContains("(5,5)");
        }
Exemplo n.º 10
0
 public void RootNamespace()
 {
     Vbc t = new Vbc();
     t.RootNamespace = @"parm1 /out:c:\windows\system32\notepad.exe";
     CommandLine.ValidateNoParameterStartsWith(t, "/out");
 }
Exemplo n.º 11
0
 public void Imports()
 {
     Vbc t = new Vbc();
     t.Imports = new TaskItem[] { new TaskItem(@"parm1 /out:c:\windows\system32\notepad.exe") };
     CommandLine.ValidateNoParameterStartsWith(t, "/out");
 }
Exemplo n.º 12
0
 public void Resources()
 {
     Vbc t = new Vbc();
     t.References = new TaskItem[]
     {
         new TaskItem("parm0"),
         new TaskItem(@"parm1 /out:c:\windows\system32\notepad.exe")
     };
     CommandLine.ValidateNoParameterStartsWith(t, "/out");
 }
Exemplo n.º 13
0
 public void OutputAssembly()
 {
     Vbc t = new Vbc();
     t.OutputAssembly = new TaskItem(@"parm1 /out:c:\windows\system32\notepad.exe");
     CommandLine.ValidateHasParameter(t, @"/out:parm1 /out:c:\windows\system32\notepad.exe");
 }
Exemplo n.º 14
0
 public void MainEntryPoint()
 {
     Vbc t = new Vbc();
     t.MainEntryPoint = @"parm1 /out:c:\windows\system32\notepad.exe";
     CommandLine.ValidateNoParameterStartsWith(t, "/out");
 }
Exemplo n.º 15
0
 public void LinkResources()
 {
     Vbc t = new Vbc();
     t.KeyFile = @"parm1 /out:c:\windows\system32\notepad.exe";
     CommandLine.ValidateNoParameterStartsWith(t, "/out");
 }
Exemplo n.º 16
0
 public void MultipleResponseFiles()
 {
     Vbc t = new Vbc();
     t.ResponseFiles = new TaskItem[]
         {
             new TaskItem(@"1.rsp"),
             new TaskItem(@"2.rsp"),
             new TaskItem(@"3.rsp"),
             new TaskItem(@"4.rsp")
         };
     CommandLine.ValidateContains(t, "@1.rsp @2.rsp @3.rsp @4.rsp", true);
 }
Exemplo n.º 17
0
 public void SingleResponseFile()
 {
     Vbc t = new Vbc();
     t.ResponseFiles = new TaskItem[]
         {
             new TaskItem(@"1.rsp")
         };
     CommandLine.ValidateHasParameter(t, "@1.rsp");
 }
Exemplo n.º 18
0
 public void SdkPath()
 {
     Vbc t = new Vbc();
     t.SdkPath = @"parm1 /out:c:\windows\system32\notepad.exe";
     CommandLine.ValidateNoParameterStartsWith(t, "/out");
 }
Exemplo n.º 19
0
        public void ParseError_StandardVbcErrorWithColon()
        {
            Vbc t = new Vbc();
            t.BuildEngine = new MockEngine();

            string error1 = "d:\\scratch\\607654\\Module1.vb(5) : error BC30800: Method arguments must be enclosed in parentheses : Don't you think?";
            string error2 = "";
            string error3 = "    Ed Sub";
            string error4 = "       ~~~";

            t.ParseVBErrorOrWarning(error1, MessageImportance.High);
            t.ParseVBErrorOrWarning(error2, MessageImportance.High);
            t.ParseVBErrorOrWarning(error3, MessageImportance.High);
            t.ParseVBErrorOrWarning(error4, MessageImportance.High);

            Assert.IsTrue((t.BuildEngine as MockEngine).Errors >= 1, "Should be at least one error");
            (t.BuildEngine as MockEngine).AssertLogContains("BC30800");
            (t.BuildEngine as MockEngine).AssertLogContains("(5,8)");
        }
Exemplo n.º 20
0
 public void OptionStrictOffNowarnsEmpty()
 {
     Vbc t = new Vbc();
     t.OptionStrict = false;
     t.DisabledWarnings = "";
     CommandLine.ValidateHasParameter(t, "/optionstrict:custom"); // we shuold be custom if no warnings are disabled
 }
Exemplo n.º 21
0
        public void ParseError_ProjectLevelVbcError()
        {
            Vbc t = new Vbc();
            t.BuildEngine = new MockEngine();

            string error = "vbc : error BC30573: Error in project-level import '<xmlns=\"hi\">' at '<xmlns=\"hi\">' : XML namespace prefix '' is already declared";

            t.ParseVBErrorOrWarning(error, MessageImportance.High);

            Assert.IsTrue((t.BuildEngine as MockEngine).Errors >= 1, "Should be at least one error");
            (t.BuildEngine as MockEngine).AssertLogContains("BC30573");
        }
Exemplo n.º 22
0
 public void OptionStrictOffNoWarnsPresent()
 {
     // When the below warnings are set to NONE, we are effectively Option Strict-.  But because we don't want the msbuild task
     // to have to know the current set of disabled warnings that implies option strict-, we just set option strict:custom
     // with the understanding that we get the same behavior as option strict- since we are passing the /nowarn line on that
     // contains all the warnings OptionStrict- would disable anyway.
     Vbc t = new Vbc();
     t.OptionStrict = false;
     t.DisabledWarnings = "41999,42016,42017,42018,42019,42020,42021,42022,42032,42036";
     CommandLine.ValidateHasParameter(t, "/optionstrict:custom");
     t.DisabledWarnings = "/nowarn:41999,42016,42017,42018,42019,42020,42021,42022,42032,42036";
 }
Exemplo n.º 23
0
        public void ParseError_TwoProjectLevelErrors()
        {
            Vbc t = new Vbc();
            t.BuildEngine = new MockEngine();

            string error1 = "vbc : error BC30205: Error in project-level import '<xmlns='bye'>, <xmlns='byebye'>' at '<xmlns='bye'>, ' : End of statement expected.";
            string error2 = "vbc : error BC30573: Error in project-level import '<xmlns=\"hi\">' at '<xmlns=\"hi\">' : XML namespace prefix '' is already declared";

            t.ParseVBErrorOrWarning(error1, MessageImportance.High);
            t.ParseVBErrorOrWarning(error2, MessageImportance.High);

            Assert.IsTrue((t.BuildEngine as MockEngine).Errors >= 2, "Should be at least two errors");
            (t.BuildEngine as MockEngine).AssertLogContains("BC30573");
            (t.BuildEngine as MockEngine).AssertLogContains("BC30205");
        }
Exemplo n.º 24
0
 public void OptionStrictOnNoWarnsUndefined()
 {
     Vbc t = new Vbc();
     t.OptionStrict = true;
     t.DisabledWarnings = "";
     CommandLine.ValidateHasParameter(t, "/optionstrict+");
 }
Exemplo n.º 25
0
        public void MovePDBFile_SameNameandFileAlreadyExists()
        {
            string tempDirectory = Path.Combine(Path.GetTempPath(), "MovePDBFile_SmeNameandFileAlreadyExists");
            try
            {
                if (Directory.Exists(tempDirectory))
                {
                    FileUtilities.DeleteDirectoryNoThrow(tempDirectory, true);
                }

                Directory.CreateDirectory(tempDirectory);

                string outputAssemblyPath = Path.Combine(tempDirectory, "Out.dll");
                string newoutputAssemblyPath = Path.Combine(tempDirectory, "Out.pdb");

                File.WriteAllText(outputAssemblyPath, "Hello");
                File.WriteAllText(newoutputAssemblyPath, "Hello");

                Vbc t = new Vbc();
                t.BuildEngine = new MockEngine();
                t.PdbFile = newoutputAssemblyPath;
                t.MovePdbFileIfNecessary(outputAssemblyPath);

                FileInfo newPDBInfo = new FileInfo(newoutputAssemblyPath);

                Assert.IsTrue(newPDBInfo.Exists);
                ((MockEngine)t.BuildEngine).MockLogger.AssertNoErrors();
            }
            finally
            {
                if (Directory.Exists(tempDirectory))
                {
                    FileUtilities.DeleteDirectoryNoThrow(tempDirectory, true);
                }
            }
        }
Exemplo n.º 26
0
 public void OptionStrictOnNoWarnsPresent()
 {
     Vbc t = new Vbc();
     t.OptionStrict = true;
     t.DisabledWarnings = "41999";
     CommandLine.ValidateHasParameter(t, "/optionstrict+");
     t.DisabledWarnings = "/nowarn:41999";
 }
Exemplo n.º 27
0
        public void NoAnalyzers_CommandLine()
        {
            Vbc vbc = new Vbc();

            CommandLine.ValidateNoParameterStartsWith(vbc, "/analyzer");
        }
Exemplo n.º 28
0
 public void OptionStrictType1()
 {
     Vbc t = new Vbc();
     t.OptionStrict = true;
     t.OptionStrictType = "custom";
     CommandLine.ValidateContains(t, "/optionstrict+ /optionstrict:custom", true);
 }
Exemplo n.º 29
0
        public void MultipleAnalyzers_CommandLine()
        {
            Vbc vbc = new Vbc();
            vbc.Analyzers = new TaskItem[]
            {
                new TaskItem("Foo.dll"),
                new TaskItem("Bar.dll")
            };

            CommandLine.ValidateHasParameter(vbc, "/analyzer:Foo.dll");
            CommandLine.ValidateHasParameter(vbc, "/analyzer:Bar.dll");
        }
Exemplo n.º 30
0
 public void OptionStrictType2()
 {
     Vbc t = new Vbc();
     t.OptionStrictType = "custom";
     CommandLine.ValidateContains(t, "/optionstrict:custom", true);
     CommandLine.ValidateDoesNotContain(t, "/optionstrict-", true);
 }