From 025bda7f30e73f537ab5c983664e65b788e6485c Mon Sep 17 00:00:00 2001 From: Z Chen <13544267+zijchen@users.noreply.github.com> Date: Fri, 19 Apr 2024 11:05:29 -0700 Subject: [PATCH 1/8] Update Microsoft.Build.Sql.csproj --- src/Microsoft.Build.Sql/Microsoft.Build.Sql.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.Build.Sql/Microsoft.Build.Sql.csproj b/src/Microsoft.Build.Sql/Microsoft.Build.Sql.csproj index db818be..9468902 100644 --- a/src/Microsoft.Build.Sql/Microsoft.Build.Sql.csproj +++ b/src/Microsoft.Build.Sql/Microsoft.Build.Sql.csproj @@ -13,9 +13,9 @@ - + - + From 96c061e9746e54f10fd2848ab7601facd7ce8579 Mon Sep 17 00:00:00 2001 From: Z Chen <13544267+zijchen@users.noreply.github.com> Date: Mon, 29 Jul 2024 09:44:08 -0700 Subject: [PATCH 2/8] Update ScriptDom to 161.9123.0 --- src/Microsoft.Build.Sql/Microsoft.Build.Sql.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.Build.Sql/Microsoft.Build.Sql.csproj b/src/Microsoft.Build.Sql/Microsoft.Build.Sql.csproj index 218b087..2497836 100644 --- a/src/Microsoft.Build.Sql/Microsoft.Build.Sql.csproj +++ b/src/Microsoft.Build.Sql/Microsoft.Build.Sql.csproj @@ -15,7 +15,7 @@ - + From 8b17b67d6c8d5d777aee449e3014adbc66719bc9 Mon Sep 17 00:00:00 2001 From: Zi Chen Date: Tue, 24 Sep 2024 13:09:30 -0700 Subject: [PATCH 3/8] Add target to remove included files via :r from build --- Directory.Build.props | 1 + src/Microsoft.Build.Sql/sdk/Sdk.targets | 7 +++++ test/Microsoft.Build.Sql.Tests/BuildTests.cs | 28 +++++++++++++++++++ .../Script.PostDeployment1.sql | 1 + .../VerifyBuildWithIncludeFiles/Table1.sql | 5 ++++ .../VerifyBuildWithIncludeFiles/Table2.sql | 5 ++++ 6 files changed, 47 insertions(+) create mode 100644 test/Microsoft.Build.Sql.Tests/TestData/VerifyBuildWithIncludeFiles/Script.PostDeployment1.sql create mode 100644 test/Microsoft.Build.Sql.Tests/TestData/VerifyBuildWithIncludeFiles/Table1.sql create mode 100644 test/Microsoft.Build.Sql.Tests/TestData/VerifyBuildWithIncludeFiles/Table2.sql diff --git a/Directory.Build.props b/Directory.Build.props index 2a6b458..7bb4919 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -12,6 +12,7 @@ https://github.com/microsoft/DacFx git + 162.4.92 161.9142.1 5.1.6 diff --git a/src/Microsoft.Build.Sql/sdk/Sdk.targets b/src/Microsoft.Build.Sql/sdk/Sdk.targets index 83b798b..a6057c4 100644 --- a/src/Microsoft.Build.Sql/sdk/Sdk.targets +++ b/src/Microsoft.Build.Sql/sdk/Sdk.targets @@ -63,6 +63,13 @@ + + + + + + + diff --git a/test/Microsoft.Build.Sql.Tests/BuildTests.cs b/test/Microsoft.Build.Sql.Tests/BuildTests.cs index ff344e0..ff4c154 100644 --- a/test/Microsoft.Build.Sql.Tests/BuildTests.cs +++ b/test/Microsoft.Build.Sql.Tests/BuildTests.cs @@ -361,5 +361,33 @@ public void VerifyBuildWithReleaseConfiguration() Assert.AreEqual(string.Empty, stdError); FileAssert.Exists(Path.Combine(WorkingDirectory, "bin", "Release", DatabaseProjectName + ".dacpac")); } + + [Test] + // https://github.com/microsoft/DacFx/issues/103 + public void VerifyBuildWithIncludeFiles() + { + // Post-deployment script includes Table2.sql which creates Table2, it should not be part of the model + this.AddPostDeployScripts("Script.PostDeployment1.sql"); + int exitCode = this.RunDotnetCommandOnProject("build", out _, out string stdError, "-bl"); + + // Verify success + Assert.AreEqual(0, exitCode, "Build failed with error " + stdError); + Assert.AreEqual(string.Empty, stdError); + this.VerifyDacPackage(expectPostDeployScript: true); + + // Verify the Table2 is not part of the model + using (TSqlModel model = new TSqlModel(this.GetDacpacPath())) + { + var tables = model.GetObjects(DacQueryScopes.UserDefined, ModelSchema.Table); + Assert.IsTrue(tables.Any(), "Expected at least 1 table in the model."); + foreach (var table in tables) + { + if (table.Name.ToString().IndexOf("Table2", StringComparison.OrdinalIgnoreCase) >= 0) + { + Assert.Fail("Table2 should have been excluded from the model."); + } + } + } + } } } \ No newline at end of file diff --git a/test/Microsoft.Build.Sql.Tests/TestData/VerifyBuildWithIncludeFiles/Script.PostDeployment1.sql b/test/Microsoft.Build.Sql.Tests/TestData/VerifyBuildWithIncludeFiles/Script.PostDeployment1.sql new file mode 100644 index 0000000..50ae5f7 --- /dev/null +++ b/test/Microsoft.Build.Sql.Tests/TestData/VerifyBuildWithIncludeFiles/Script.PostDeployment1.sql @@ -0,0 +1 @@ +:r Table2.sql \ No newline at end of file diff --git a/test/Microsoft.Build.Sql.Tests/TestData/VerifyBuildWithIncludeFiles/Table1.sql b/test/Microsoft.Build.Sql.Tests/TestData/VerifyBuildWithIncludeFiles/Table1.sql new file mode 100644 index 0000000..c4cde37 --- /dev/null +++ b/test/Microsoft.Build.Sql.Tests/TestData/VerifyBuildWithIncludeFiles/Table1.sql @@ -0,0 +1,5 @@ +CREATE TABLE [dbo].[Table1] +( + c1 int NOT NULL PRIMARY KEY, + c2 int NULL +) \ No newline at end of file diff --git a/test/Microsoft.Build.Sql.Tests/TestData/VerifyBuildWithIncludeFiles/Table2.sql b/test/Microsoft.Build.Sql.Tests/TestData/VerifyBuildWithIncludeFiles/Table2.sql new file mode 100644 index 0000000..4ea4ae6 --- /dev/null +++ b/test/Microsoft.Build.Sql.Tests/TestData/VerifyBuildWithIncludeFiles/Table2.sql @@ -0,0 +1,5 @@ +CREATE TABLE [dbo].[Table2] +( + c1 int NOT NULL PRIMARY KEY, + c2 int NULL +) \ No newline at end of file From cc4b6d7e20e9b4f9bdd925c3e3c8be238d3250fa Mon Sep 17 00:00:00 2001 From: Zi Chen Date: Tue, 12 Nov 2024 11:03:28 -0800 Subject: [PATCH 4/8] Update System.IO.Packaging to 8.0.1 --- src/Microsoft.Build.Sql/Microsoft.Build.Sql.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.Build.Sql/Microsoft.Build.Sql.csproj b/src/Microsoft.Build.Sql/Microsoft.Build.Sql.csproj index 2b3f573..128266f 100644 --- a/src/Microsoft.Build.Sql/Microsoft.Build.Sql.csproj +++ b/src/Microsoft.Build.Sql/Microsoft.Build.Sql.csproj @@ -18,7 +18,7 @@ - + From 039ec1af7704d134f2321af39c25694926ee3894 Mon Sep 17 00:00:00 2001 From: Zi Chen Date: Thu, 14 Nov 2024 17:35:44 -0800 Subject: [PATCH 5/8] Fix test VerifyCodeAnalyzerFromPackageReference --- test/Microsoft.Build.Sql.Tests/CodeAnalysisTests.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/Microsoft.Build.Sql.Tests/CodeAnalysisTests.cs b/test/Microsoft.Build.Sql.Tests/CodeAnalysisTests.cs index 0d74ae6..2a5ffe9 100644 --- a/test/Microsoft.Build.Sql.Tests/CodeAnalysisTests.cs +++ b/test/Microsoft.Build.Sql.Tests/CodeAnalysisTests.cs @@ -47,19 +47,19 @@ public void VerifyCodeAnalyzerFromPackageReference() // Set up and create the analyzer package string tempFolder = TestUtils.CreateTempDirectory(); TestUtils.CopyDirectoryRecursive(Path.Combine(CommonTestDataDirectory, "CodeAnalyzerSample"), tempFolder); - RunGenericDotnetCommand($"pack {Path.Combine(tempFolder, "CodeAnalyzerSample.csproj")} -o {tempFolder}", out _, out _); + RunGenericDotnetCommand($"pack {Path.Combine(tempFolder, "CodeAnalyzerSample.csproj")} -o {tempFolder} -p:Version=1.1.1-test", out _, out _); // Copy analyzer package to local Nuget source - string analyzerPackagePath = Path.Combine(tempFolder, "CodeAnalyzerSample.1.0.0.nupkg"); + string analyzerPackagePath = Path.Combine(tempFolder, "CodeAnalyzerSample.1.1.1-test.nupkg"); FileAssert.Exists(analyzerPackagePath); - File.Copy(analyzerPackagePath, Path.Combine(WorkingDirectory, "pkg", "CodeAnalyzerSample.1.0.0.nupkg")); + File.Copy(analyzerPackagePath, Path.Combine(WorkingDirectory, "pkg", "CodeAnalyzerSample.1.1.1-test.nupkg")); // Add the analyzer package as a PackageReference to the test sqlproj ProjectUtils.AddItemGroup(this.GetProjectFilePath(), "PackageReference", new string[] { "CodeAnalyzerSample" }, item => { - item.AddMetadata("Version", "1.0.0"); + item.AddMetadata("Version", "1.1.1-test"); }); // Set up code analysis properties From cdb4445f3ceede510cd4a5fb0f03e779f6648069 Mon Sep 17 00:00:00 2001 From: Zi Chen Date: Thu, 21 Nov 2024 12:03:32 -0800 Subject: [PATCH 6/8] Update DacFx to 162.5.57 --- Directory.Build.props | 2 +- src/Microsoft.Build.Sql/Microsoft.Build.Sql.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index 2a6b458..64ebc55 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -12,7 +12,7 @@ https://github.com/microsoft/DacFx git - 162.4.92 + 162.5.57 161.9142.1 5.1.6 diff --git a/src/Microsoft.Build.Sql/Microsoft.Build.Sql.csproj b/src/Microsoft.Build.Sql/Microsoft.Build.Sql.csproj index 2b3f573..128266f 100644 --- a/src/Microsoft.Build.Sql/Microsoft.Build.Sql.csproj +++ b/src/Microsoft.Build.Sql/Microsoft.Build.Sql.csproj @@ -18,7 +18,7 @@ - + From 9ab4532801dc5562c3f4b897ddecb071c48a91a6 Mon Sep 17 00:00:00 2001 From: Zi Chen Date: Thu, 21 Nov 2024 12:17:38 -0800 Subject: [PATCH 7/8] Fix merge conflict --- src/Microsoft.Build.Sql/sdk/Sdk.targets | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Microsoft.Build.Sql/sdk/Sdk.targets b/src/Microsoft.Build.Sql/sdk/Sdk.targets index 9c628c4..749994b 100644 --- a/src/Microsoft.Build.Sql/sdk/Sdk.targets +++ b/src/Microsoft.Build.Sql/sdk/Sdk.targets @@ -70,16 +70,17 @@ + + + + + + - - - - - From eece43016e19b7989c62a297369a74cfa19cfbb5 Mon Sep 17 00:00:00 2001 From: Zi Chen Date: Thu, 21 Nov 2024 13:20:26 -0800 Subject: [PATCH 8/8] Clean up extra space --- src/Microsoft.Build.Sql/sdk/Sdk.targets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.Build.Sql/sdk/Sdk.targets b/src/Microsoft.Build.Sql/sdk/Sdk.targets index 749994b..abb5a46 100644 --- a/src/Microsoft.Build.Sql/sdk/Sdk.targets +++ b/src/Microsoft.Build.Sql/sdk/Sdk.targets @@ -70,7 +70,7 @@ - +