Пример #1
0
        public void ItemIsMissingRequestedMetadata()
        {
            ITaskItem item1 = MSBuildUtil.CreateTaskItem("c:/file1.cs", new Dictionary <string, string> {
                { "ItemType", "Compile" }, { "MetadataName", "ToRetrieve" }
            });

            GenerateMSBuildEditorConfig configTask = new GenerateMSBuildEditorConfig()
            {
                MetadataItems = new[] { item1 }
            };

            configTask.Execute();

            var result = configTask.ConfigFileContents;

            Assert.Equal(@"is_global = true

[c:/file1.cs]
build_metadata.Compile.ToRetrieve = 
", result);
        }
Пример #2
0
        public void SourceLink()
        {
            var csc = new Csc();

            csc.Sources    = MSBuildUtil.CreateTaskItems("test.cs");
            csc.DebugType  = "portable";
            csc.SourceLink = @"C:\x y\z.json";
            Assert.Equal(@"/debug:portable /out:test.exe /sourcelink:""C:\x y\z.json"" test.cs", csc.GenerateResponseFileContents());

            csc            = new Csc();
            csc.Sources    = MSBuildUtil.CreateTaskItems("test.cs");
            csc.DebugType  = "portable";
            csc.SourceLink = null;
            Assert.Equal(@"/debug:portable /out:test.exe test.cs", csc.GenerateResponseFileContents());

            csc            = new Csc();
            csc.Sources    = MSBuildUtil.CreateTaskItems("test.cs");
            csc.DebugType  = "portable";
            csc.SourceLink = "";
            Assert.Equal(@"/debug:portable /out:test.exe /sourcelink: test.cs", csc.GenerateResponseFileContents());
        }
Пример #3
0
        public void SourceLink()
        {
            var vbc = new Vbc();

            vbc.Sources    = MSBuildUtil.CreateTaskItems("test.vb");
            vbc.DebugType  = "portable";
            vbc.SourceLink = @"C:\x y\z.json";
            Assert.Equal(@"/optionstrict:custom /debug:portable /out:test.exe /sourcelink:""C:\x y\z.json"" test.vb", vbc.GenerateResponseFileContents());

            vbc            = new Vbc();
            vbc.Sources    = MSBuildUtil.CreateTaskItems("test.vb");
            vbc.DebugType  = "portable";
            vbc.SourceLink = null;
            Assert.Equal(@"/optionstrict:custom /debug:portable /out:test.exe test.vb", vbc.GenerateResponseFileContents());

            vbc            = new Vbc();
            vbc.Sources    = MSBuildUtil.CreateTaskItems("test.vb");
            vbc.DebugType  = "portable";
            vbc.SourceLink = "";
            Assert.Equal(@"/optionstrict:custom /debug:portable /out:test.exe /sourcelink: test.vb", vbc.GenerateResponseFileContents());
        }
Пример #4
0
        public void DuplicateItemSpecsAreCombinedInSections()
        {
            ITaskItem item1 = MSBuildUtil.CreateTaskItem(
                "c:/file1.cs",
                new Dictionary <string, string>
            {
                { "ItemType", "Compile" },
                { "MetadataName", "ToRetrieve" },
                { "ToRetrieve", "abc123" }
            }
                );
            ITaskItem item2 = MSBuildUtil.CreateTaskItem(
                "c:/file1.cs",
                new Dictionary <string, string>
            {
                { "ItemType", "AdditionalFile" },
                { "MetadataName", "ToRetrieve" },
                { "ToRetrieve", "def456" }
            }
                );

            GenerateMSBuildEditorConfig configTask = new GenerateMSBuildEditorConfig()
            {
                MetadataItems = new[] { item1, item2 }
            };

            configTask.Execute();

            var result = configTask.ConfigFileContents;

            Assert.Equal(
                @"is_global = true

[c:/file1.cs]
build_metadata.Compile.ToRetrieve = abc123
build_metadata.AdditionalFile.ToRetrieve = def456
",
                result
                );
        }
Пример #5
0
        public void Embed()
        {
            var vbc = new Vbc();

            vbc.Sources       = MSBuildUtil.CreateTaskItems("test.vb");
            vbc.DebugType     = "portable";
            vbc.EmbeddedFiles = MSBuildUtil.CreateTaskItems(@"test.vb", @"test.txt");
            Assert.Equal(@"/optionstrict:custom /debug:portable /out:test.exe /embed:test.vb /embed:test.txt test.vb", vbc.GenerateResponseFileContents());

            vbc               = new Vbc();
            vbc.Sources       = MSBuildUtil.CreateTaskItems("test.vb");
            vbc.DebugType     = "portable";
            vbc.EmbeddedFiles = MSBuildUtil.CreateTaskItems(@"C:\x y\z.json");
            Assert.Equal(@"/optionstrict:custom /debug:portable /out:test.exe /embed:""C:\x y\z.json"" test.vb", vbc.GenerateResponseFileContents());

            vbc               = new Vbc();
            vbc.Sources       = MSBuildUtil.CreateTaskItems("test.vb");
            vbc.DebugType     = "portable";
            vbc.EmbeddedFiles = null;
            Assert.Equal(@"/optionstrict:custom /debug:portable /out:test.exe test.vb", vbc.GenerateResponseFileContents());

            vbc               = new Vbc();
            vbc.Sources       = MSBuildUtil.CreateTaskItems("test.vb");
            vbc.DebugType     = "full";
            vbc.EmbeddedFiles = MSBuildUtil.CreateTaskItems();
            Assert.Equal(@"/optionstrict:custom /debug:full /out:test.exe test.vb", vbc.GenerateResponseFileContents());

            vbc               = new Vbc();
            vbc.Sources       = MSBuildUtil.CreateTaskItems("a;b.vb");
            vbc.DebugType     = "full";
            vbc.EmbeddedFiles = MSBuildUtil.CreateTaskItems("a;b.vb");
            Assert.Equal(@"/optionstrict:custom /debug:full /out:""a;b.exe"" /embed:""a;b.vb"" ""a;b.vb""", vbc.GenerateResponseFileContents());

            vbc               = new Vbc();
            vbc.Sources       = MSBuildUtil.CreateTaskItems("a, b.vb");
            vbc.DebugType     = "full";
            vbc.EmbeddedFiles = MSBuildUtil.CreateTaskItems("a, b.vb");
            Assert.Equal(@"/optionstrict:custom /debug:full /out:""a, b.exe"" /embed:""a, b.vb"" ""a, b.vb""", vbc.GenerateResponseFileContents());
        }
Пример #6
0
        public void EmbedAllSources()
        {
            var vbc = new Vbc();

            vbc.Sources         = MSBuildUtil.CreateTaskItems("test.vb");
            vbc.EmbeddedFiles   = MSBuildUtil.CreateTaskItems(@"test.vb", @"test.txt");
            vbc.EmbedAllSources = true;

            Assert.Equal(
                @"/optionstrict:custom /out:test.exe /embed /embed:test.vb /embed:test.txt test.vb",
                vbc.GenerateResponseFileContents()
                );

            vbc                 = new Vbc();
            vbc.Sources         = MSBuildUtil.CreateTaskItems("test.vb");
            vbc.EmbedAllSources = true;

            Assert.Equal(
                @"/optionstrict:custom /out:test.exe /embed test.vb",
                vbc.GenerateResponseFileContents()
                );
        }
Пример #7
0
        public void SkipAnalyzersFlag()
        {
            var csc = new Csc();

            csc.Sources       = MSBuildUtil.CreateTaskItems("test.cs");
            csc.SkipAnalyzers = true;
            Assert.Equal(
                "/out:test.exe /skipanalyzers+ test.cs",
                csc.GenerateResponseFileContents()
                );

            csc               = new Csc();
            csc.Sources       = MSBuildUtil.CreateTaskItems("test.cs");
            csc.SkipAnalyzers = false;
            Assert.Equal(
                "/out:test.exe /skipanalyzers- test.cs",
                csc.GenerateResponseFileContents()
                );

            csc         = new Csc();
            csc.Sources = MSBuildUtil.CreateTaskItems("test.cs");
            Assert.Equal("/out:test.exe test.cs", csc.GenerateResponseFileContents());
        }
Пример #8
0
        public void EmptyCscToolExe()
        {
            var csc = new Csc();

            csc.ToolPath = Path.Combine("path", "to", "custom_csc");
            csc.ToolExe  = "";
            csc.Sources  = MSBuildUtil.CreateTaskItems("test.cs");
            Assert.Equal("", csc.GenerateCommandLine());
            // StartsWith because it can be csc.exe or csc.dll
            Assert.StartsWith(
                Path.Combine("path", "to", "custom_csc", "csc."),
                csc.GeneratePathToTool()
                );

            csc          = new Csc();
            csc.ToolPath = Path.Combine("path", "to", "custom_csc");
            csc.Sources  = MSBuildUtil.CreateTaskItems("test.cs");
            Assert.Equal("", csc.GenerateCommandLine());
            Assert.StartsWith(
                Path.Combine("path", "to", "custom_csc", "csc."),
                csc.GeneratePathToTool()
                );
        }
Пример #9
0
        public void DeterministicFlag()
        {
            var csc = new Csc();

            csc.Sources       = MSBuildUtil.CreateTaskItems("test.cs");
            csc.Deterministic = true;
            Assert.Equal(
                "/out:test.exe /deterministic+ test.cs",
                csc.GenerateResponseFileContents()
                );

            csc               = new Csc();
            csc.Sources       = MSBuildUtil.CreateTaskItems("test.cs");
            csc.Deterministic = false;
            Assert.Equal(
                "/out:test.exe /deterministic- test.cs",
                csc.GenerateResponseFileContents()
                );

            csc         = new Csc();
            csc.Sources = MSBuildUtil.CreateTaskItems("test.cs");
            Assert.Equal("/out:test.exe test.cs", csc.GenerateResponseFileContents());
        }
Пример #10
0
        public void PropertiesAreGeneratedInGlobalSection()
        {
            ITaskItem property1 = MSBuildUtil.CreateTaskItem("Property1", new Dictionary <string, string> {
                { "Value", "abc123" }
            });
            ITaskItem property2 = MSBuildUtil.CreateTaskItem("Property2", new Dictionary <string, string> {
                { "Value", "def456" }
            });

            GenerateMSBuildEditorConfig configTask = new GenerateMSBuildEditorConfig()
            {
                PropertyItems = new[] { property1, property2 }
            };

            configTask.Execute();

            var result = configTask.ConfigFileContents;

            Assert.Equal(@"is_global = true
build_property.Property1 = abc123
build_property.Property2 = def456
", result);
        }
Пример #11
0
        public void Embed()
        {
            var csc = new Csc();

            csc.Sources       = MSBuildUtil.CreateTaskItems("test.cs");
            csc.DebugType     = "portable";
            csc.EmbeddedFiles = MSBuildUtil.CreateTaskItems(@"test.cs", @"test.txt");
            Assert.Equal(
                @"/debug:portable /out:test.exe /embed:test.cs /embed:test.txt test.cs",
                csc.GenerateResponseFileContents()
                );

            csc               = new Csc();
            csc.Sources       = MSBuildUtil.CreateTaskItems("test.cs");
            csc.DebugType     = "portable";
            csc.EmbeddedFiles = MSBuildUtil.CreateTaskItems(@"C:\x y\z.json");
            Assert.Equal(
                @"/debug:portable /out:test.exe /embed:""C:\x y\z.json"" test.cs",
                csc.GenerateResponseFileContents()
                );

            csc               = new Csc();
            csc.Sources       = MSBuildUtil.CreateTaskItems("test.cs");
            csc.DebugType     = "portable";
            csc.EmbeddedFiles = null;
            Assert.Equal(
                @"/debug:portable /out:test.exe test.cs",
                csc.GenerateResponseFileContents()
                );

            csc               = new Csc();
            csc.Sources       = MSBuildUtil.CreateTaskItems("test.cs");
            csc.DebugType     = "full";
            csc.EmbeddedFiles = MSBuildUtil.CreateTaskItems();
            Assert.Equal(@"/debug:full /out:test.exe test.cs", csc.GenerateResponseFileContents());
        }
Пример #12
0
        public void ChecksumAlgorithmOption()
        {
            var csc = new Csc();

            csc.Sources           = MSBuildUtil.CreateTaskItems("test.cs");
            csc.ChecksumAlgorithm = "sha256";
            Assert.Equal(
                "/out:test.exe /checksumalgorithm:sha256 test.cs",
                csc.GenerateResponseFileContents()
                );

            csc                   = new Csc();
            csc.Sources           = MSBuildUtil.CreateTaskItems("test.cs");
            csc.ChecksumAlgorithm = null;
            Assert.Equal("/out:test.exe test.cs", csc.GenerateResponseFileContents());

            csc                   = new Csc();
            csc.Sources           = MSBuildUtil.CreateTaskItems("test.cs");
            csc.ChecksumAlgorithm = "";
            Assert.Equal(
                "/out:test.exe /checksumalgorithm: test.cs",
                csc.GenerateResponseFileContents()
                );
        }
Пример #13
0
        public void PropertiesAreGeneratedBeforeItems()
        {
            ITaskItem item1 = MSBuildUtil.CreateTaskItem(
                "c:/file1.cs",
                new Dictionary <string, string>
            {
                { "ItemType", "Compile" },
                { "MetadataName", "ToRetrieve" },
                { "ToRetrieve", "abc123" }
            }
                );
            ITaskItem item2 = MSBuildUtil.CreateTaskItem(
                "c:/file2.cs",
                new Dictionary <string, string>
            {
                { "ItemType", "Compile" },
                { "MetadataName", "ToRetrieve" },
                { "ToRetrieve", "def456" }
            }
                );
            ITaskItem item3 = MSBuildUtil.CreateTaskItem(
                "c:/file3.cs",
                new Dictionary <string, string>
            {
                { "ItemType", "AdditionalFiles" },
                { "MetadataName", "ToRetrieve" },
                { "ToRetrieve", "ghi789" }
            }
                );
            ITaskItem item4 = MSBuildUtil.CreateTaskItem(
                "c:/file1.cs",
                new Dictionary <string, string>
            {
                { "ItemType", "AdditionalFiles" },
                { "MetadataName", "ToRetrieve" },
                { "ToRetrieve", "jkl012" }
            }
                );

            ITaskItem property1 = MSBuildUtil.CreateTaskItem(
                "Property1",
                new Dictionary <string, string> {
                { "Value", "abc123" }
            }
                );
            ITaskItem property2 = MSBuildUtil.CreateTaskItem(
                "Property2",
                new Dictionary <string, string> {
                { "Value", "def456" }
            }
                );

            GenerateMSBuildEditorConfig configTask = new GenerateMSBuildEditorConfig()
            {
                MetadataItems = new[] { item1, item2, item3, item4 },
                PropertyItems = new[] { property1, property2 }
            };

            configTask.Execute();

            var result = configTask.ConfigFileContents;

            Assert.Equal(
                @"is_global = true
build_property.Property1 = abc123
build_property.Property2 = def456

[c:/file1.cs]
build_metadata.Compile.ToRetrieve = abc123
build_metadata.AdditionalFiles.ToRetrieve = jkl012

[c:/file2.cs]
build_metadata.Compile.ToRetrieve = def456

[c:/file3.cs]
build_metadata.AdditionalFiles.ToRetrieve = ghi789
",
                result
                );
        }
Пример #14
0
 public void SingleSource()
 {
     var csc = new Csc();
     csc.Sources = MSBuildUtil.CreateTaskItems("test.cs");
     Assert.Equal("/out:test.exe test.cs", csc.GenerateResponseFileContents());
 }