From aa683ac4ec4c6ce746776a2a316309fe6a7d1740 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Matou=C5=A1ek?= Date: Thu, 4 Jan 2018 14:18:50 -0800 Subject: [PATCH] Add EmbedAllSources build task parameter (#23656) --- .../Core/MSBuildTask/ManagedCompiler.cs | 11 ++++++++++ .../MSBuildTask/Microsoft.CSharp.Core.targets | 1 + .../Microsoft.VisualBasic.Core.targets | 1 + .../Core/MSBuildTaskTests/CscTests.cs | 21 +++++++++++++++++-- .../Core/MSBuildTaskTests/VbcTests.cs | 21 +++++++++++++++++-- 5 files changed, 51 insertions(+), 4 deletions(-) diff --git a/src/Compilers/Core/MSBuildTask/ManagedCompiler.cs b/src/Compilers/Core/MSBuildTask/ManagedCompiler.cs index 3388cd898982e..0ac924b31628f 100644 --- a/src/Compilers/Core/MSBuildTask/ManagedCompiler.cs +++ b/src/Compilers/Core/MSBuildTask/ManagedCompiler.cs @@ -63,6 +63,12 @@ public ITaskItem[] EmbeddedFiles get { return (ITaskItem[])_store[nameof(EmbeddedFiles)]; } } + public bool EmbedAllSources + { + set { _store[nameof(EmbedAllSources)] = value; } + get { return _store.GetOrDefault(nameof(EmbedAllSources), false); } + } + public ITaskItem[] Analyzers { set { _store[nameof(Analyzers)] = value; } @@ -845,6 +851,11 @@ private void AddAdditionalFilesToCommandLine(CommandLineBuilderExtension command /// private void AddEmbeddedFilesToCommandLine(CommandLineBuilderExtension commandLine) { + if (EmbedAllSources) + { + commandLine.AppendSwitch("/embed"); + } + if (EmbeddedFiles != null) { foreach (ITaskItem embeddedFile in EmbeddedFiles) diff --git a/src/Compilers/Core/MSBuildTask/Microsoft.CSharp.Core.targets b/src/Compilers/Core/MSBuildTask/Microsoft.CSharp.Core.targets index 25c87da889937..48116d820e416 100644 --- a/src/Compilers/Core/MSBuildTask/Microsoft.CSharp.Core.targets +++ b/src/Compilers/Core/MSBuildTask/Microsoft.CSharp.Core.targets @@ -98,6 +98,7 @@ DelaySign="$(DelaySign)" DisabledWarnings="$(NoWarn)" DocumentationFile="@(DocFileItem)" + EmbedAllSources="$(EmbedAllSources)" EmbeddedFiles="@(EmbeddedFiles)" EmitDebugInformation="$(DebugSymbols)" EnvironmentVariables="$(CscEnvironment)" diff --git a/src/Compilers/Core/MSBuildTask/Microsoft.VisualBasic.Core.targets b/src/Compilers/Core/MSBuildTask/Microsoft.VisualBasic.Core.targets index 0be5bb78bd3e3..6d544e6f9fb94 100644 --- a/src/Compilers/Core/MSBuildTask/Microsoft.VisualBasic.Core.targets +++ b/src/Compilers/Core/MSBuildTask/Microsoft.VisualBasic.Core.targets @@ -84,6 +84,7 @@ DelaySign="$(DelaySign)" DisabledWarnings="$(NoWarn)" DocumentationFile="@(DocFileItem)" + EmbedAllSources="$(EmbedAllSources)" EmbeddedFiles="@(EmbeddedFiles)" EmitDebugInformation="$(DebugSymbols)" EnvironmentVariables="$(VbcEnvironment)" diff --git a/src/Compilers/Core/MSBuildTaskTests/CscTests.cs b/src/Compilers/Core/MSBuildTaskTests/CscTests.cs index 762e17426e032..5048123ecfb71 100644 --- a/src/Compilers/Core/MSBuildTaskTests/CscTests.cs +++ b/src/Compilers/Core/MSBuildTaskTests/CscTests.cs @@ -292,9 +292,26 @@ public void Embed() csc = new Csc(); csc.Sources = MSBuildUtil.CreateTaskItems("test.cs"); - csc.DebugType = "portable"; + csc.DebugType = "full"; csc.EmbeddedFiles = MSBuildUtil.CreateTaskItems(); - Assert.Equal(@"/debug:portable /out:test.exe test.cs", csc.GenerateResponseFileContents()); + Assert.Equal(@"/debug:full /out:test.exe test.cs", csc.GenerateResponseFileContents()); + } + + [Fact] + public void EmbedAllSources() + { + var csc = new Csc(); + csc.Sources = MSBuildUtil.CreateTaskItems("test.cs"); + csc.EmbeddedFiles = MSBuildUtil.CreateTaskItems(@"test.cs", @"test.txt"); + csc.EmbedAllSources = true; + + Assert.Equal(@"/out:test.exe /embed /embed:test.cs /embed:test.txt test.cs", csc.GenerateResponseFileContents()); + + csc = new Csc(); + csc.Sources = MSBuildUtil.CreateTaskItems("test.cs"); + csc.EmbedAllSources = true; + + Assert.Equal(@"/out:test.exe /embed test.cs", csc.GenerateResponseFileContents()); } [Fact] diff --git a/src/Compilers/Core/MSBuildTaskTests/VbcTests.cs b/src/Compilers/Core/MSBuildTaskTests/VbcTests.cs index 666526fc82452..d4484c00b98a6 100644 --- a/src/Compilers/Core/MSBuildTaskTests/VbcTests.cs +++ b/src/Compilers/Core/MSBuildTaskTests/VbcTests.cs @@ -289,9 +289,26 @@ public void Embed() vbc = new Vbc(); vbc.Sources = MSBuildUtil.CreateTaskItems("test.vb"); - vbc.DebugType = "portable"; + vbc.DebugType = "full"; vbc.EmbeddedFiles = MSBuildUtil.CreateTaskItems(); - Assert.Equal(@"/optionstrict:custom /debug:portable /out:test.exe test.vb", vbc.GenerateResponseFileContents()); + Assert.Equal(@"/optionstrict:custom /debug:full /out:test.exe test.vb", vbc.GenerateResponseFileContents()); + } + + [Fact] + 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()); } [Fact]