Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change default target framework to netstandard2.1 #391

Merged
merged 20 commits into from
Feb 16, 2024
Merged
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
1 change: 1 addition & 0 deletions src/Microsoft.Build.Sql/sdk/Sdk.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<NetCoreBuild Condition="'$(NetCoreBuild)' == '' And '$(MSBuildRuntimeType)' == 'Core'">true</NetCoreBuild>
<NetCoreBuild Condition="'$(NetCoreBuild)' == '' And '$(MSBuildRuntimeType)' == 'Full'">false</NetCoreBuild>
<NETCoreTargetsPath Condition="$(NETCoreTargetsPath) == ''">$(MSBuildThisFileDirectory)..\tools\netstandard2.1</NETCoreTargetsPath>
<TargetFramework Condition="'$(TargetFramework)' == '' AND '$(NetCoreBuild)' == 'true'">netstandard2.1</TargetFramework>
</PropertyGroup>

<!-- Defaults from SSDT -->
Expand Down
1 change: 1 addition & 0 deletions src/Microsoft.Build.Sql/sdk/Sdk.targets
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<Import Condition="'$(NetCoreBuild)' != 'true' AND '$(SQLDBExtensionsRefPath)' == ''" Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\SSDT\Microsoft.Data.Tools.Schema.SqlTasks.targets" />

<Import Condition="'$(NetCoreBuild)' == 'true'" Project="$(MSBuildSdksPath)/Microsoft.NET.Sdk/targets/Microsoft.NET.DefaultAssemblyInfo.targets" />
<Import Condition="'$(NetCoreBuild)' == 'true'" Project="$(MSBuildSdksPath)/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets" />
<Import Condition="'$(NetCoreBuild)' == 'true'" Project="$(MSBuildSdksPath)/NuGet.Build.Tasks.Pack/build/NuGet.Build.Tasks.Pack.targets" />

<!-- Add dacpac file BuiltProjectOutputGroupOutput, so that it will get included in the NuGet package by the Pack target -->
Expand Down
62 changes: 62 additions & 0 deletions test/Microsoft.Build.Sql.Tests/BuildTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,5 +224,67 @@ public void VerifyBuildWithCentralPackageManagement()
Assert.AreEqual(string.Empty, stdError);
this.VerifyDacPackage();
}

[Test]
// https://github.com/microsoft/DacFx/issues/278
public void VerifyBuildWithTransitiveProjectReferences()
{
string projectA = Path.Combine(WorkingDirectory, "A", "A.sqlproj");
string projectB = Path.Combine(WorkingDirectory, "B", "B.sqlproj");

// Add A.sqlproj as a reference in B.sqlproj
ProjectUtils.AddItemGroup(projectB, "ProjectReference", new string[] { projectA });

// Add B.sqlproj as a reference in the main project
this.AddProjectReference(projectB);

// Build and verify a.dacpac is copied to the output directory
int exitCode = this.RunDotnetCommandOnProject("build", out string stdOutput, out string stdError);
Assert.AreEqual(0, exitCode, "Build failed with error " + stdError);
Assert.AreEqual(string.Empty, stdError);
this.VerifyDacPackage();
FileAssert.Exists(Path.Combine(this.GetOutputDirectory(), "A.dacpac"));
FileAssert.Exists(Path.Combine(this.GetOutputDirectory(), "B.dacpac"));
}

[Test]
[TestCase("net46")]
[TestCase("net461")]
[TestCase("net462")]
[TestCase("net47")]
[TestCase("net471")]
[TestCase("net472")]
[TestCase("net48")]
[TestCase("net481")]
[TestCase("netstandard2.1")]
[TestCase("netcoreapp3.1")]
#if NET5_0_OR_GREATER
[TestCase("net5.0")]
#endif
#if NET6_0_OR_GREATER
[TestCase("net6.0")]
#endif
#if NET7_0_OR_GREATER
[TestCase("net7.0")]
#endif
#if NET8_0_OR_GREATER
[TestCase("net8.0")]
#endif
// https://github.com/microsoft/DacFx/issues/330
public void VerifyBuildWithDifferentTargetFrameworks(string targetFramework)
{

ProjectUtils.AddProperties(this.GetProjectFilePath(), new Dictionary<string, string>()
{
{ "TargetFramework", targetFramework }
});

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();
}
}
}
4 changes: 2 additions & 2 deletions test/Microsoft.Build.Sql.Tests/DotnetTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public abstract class DotnetTestBase

protected string WorkingDirectory
{
get { return Path.Combine(TestContext.CurrentContext.WorkDirectory, TestContext.CurrentContext.Test.Name); }
get { return Path.Combine(TestContext.CurrentContext.WorkDirectory, TestUtils.EscapeTestName(TestContext.CurrentContext.Test.Name)); }
}

protected string CommonTestDataDirectory
Expand All @@ -33,7 +33,7 @@ protected string CommonTestDataDirectory

protected string CurrentTestDataDirectory
{
get { return Path.Combine(this.CommonTestDataDirectory, TestContext.CurrentContext.Test.Name); }
get { return Path.Combine(this.CommonTestDataDirectory, TestUtils.EscapeTestName(TestContext.CurrentContext.Test.Name)); }
}

[SetUp]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build">
<Sdk Name="Microsoft.Build.Sql" Version="1.0.0" />
<PropertyGroup>
<Name>A</Name>
<DSP>Microsoft.Data.Tools.Schema.Sql.Sql150DatabaseSchemaProvider</DSP>
<ModelCollation>1033, CI</ModelCollation>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build">
<Sdk Name="Microsoft.Build.Sql" Version="1.0.0" />
<PropertyGroup>
<Name>B</Name>
<DSP>Microsoft.Data.Tools.Schema.Sql.Sql150DatabaseSchemaProvider</DSP>
<ModelCollation>1033, CI</ModelCollation>
</PropertyGroup>
</Project>
5 changes: 5 additions & 0 deletions test/Microsoft.Build.Sql.Tests/TestUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,10 @@ public static void CopyDirectoryRecursive(string sourceDirectoryPath, string tar
CopyDirectoryRecursive(subDir.FullName, destDirName);
}
}

public static string EscapeTestName(string testName)
{
return testName.Replace("\"", "_");
}
}
}