Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Microsoft.Build.Sql/sdk/Sdk.props
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@
</PropertyGroup>

<ItemDefinitionGroup>
<Build>
<!-- Default AnsiNulls and QuotedIdentifier to On for SQL files to match the expected behavior.
Without these defaults, schema compare generates unwanted SET ANSI_NULLS OFF commands. -->
<AnsiNulls>On</AnsiNulls>
<QuotedIdentifier>On</QuotedIdentifier>
</Build>
<ProjectReference>
<!--
Setting ReferenceOutputAssembly skips target framework cross-project validation in NuGet. Since database projects don't define runtime
Expand Down
27 changes: 27 additions & 0 deletions test/Microsoft.Build.Sql.Tests/BuildTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,33 @@ public void VersionCheckTest()
FileAssert.Exists(NuGetClient.GetVersionCacheFilePath("Microsoft.Build.Sql"), "Version cache file should exist after fetching the version.");
}

[Test]
[Description("Verifies that Build items default to AnsiNulls ON and QuotedIdentifier ON.")]
// https://github.com/microsoft/DacFx/issues/172
public void VerifyBuildItemDefaultAnsiNullsOn()
{
// Add a target that prints the AnsiNulls and QuotedIdentifier metadata for Build items
ProjectUtils.AddTarget(GetProjectFilePath(), "PrintBuildItemMetadata", target =>
{
target.AfterTargets = "AfterBuild";
var messageTask = target.AddTask("Message");
messageTask.SetParameter("Text", "BuildItemMetadata: AnsiNulls=%(Build.AnsiNulls), QuotedIdentifier=%(Build.QuotedIdentifier)");
messageTask.SetParameter("Importance", "high");
});

int exitCode = this.RunDotnetCommandOnProject("build", out string stdOutput, out string stdError);

// Verify success
Assert.AreEqual(0, exitCode, "Build failed with error " + stdError);
Assert.AreEqual(string.Empty, stdError);
this.VerifyDacPackage();

// Verify the build output shows AnsiNulls=On and QuotedIdentifier=On
StringAssert.Contains("AnsiNulls=On", stdOutput, "Expected AnsiNulls=On in build output for Build items.");
StringAssert.Contains("QuotedIdentifier=On", stdOutput, "Expected QuotedIdentifier=On in build output for Build items.");
Assert.IsFalse(stdOutput.Contains("AnsiNulls=Off"), "Build items should not have AnsiNulls=Off.");
}

#if !NETFRAMEWORK
[Test]
[Description("Verifies that a SQL project can be added to a .sln solution and built via dotnet sln add.")]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CREATE TABLE [dbo].[Table1]
(
c1 int NOT NULL PRIMARY KEY,
c2 int NULL
)
Loading