Skip to content

Commit

Permalink
Change default target framework to netstandard2.1 (#391)
Browse files Browse the repository at this point in the history
* Add pr-validation

* Add DacFx.sln to tests

* Add dotnet pack command

* Change default target to netstandard2.1

* Add NetcoreBuild property

* Add a test for #330

* Check for dotnet in DOTNET_INSTALL_DIR

* Use /usr/share/dotnet

* Change dotnet variable and fail fast

* Fix matrix

* Add dotnet restore

* Add target framework to dotnet restore

* Revert yml changes

* Try matrix again

* Change fail fast to false

* Add target framework

* Add test for #278

* Move target framework to sdk.props
  • Loading branch information
zijchen authored Feb 16, 2024
1 parent f0f68e5 commit 3e9dea4
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 2 deletions.
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("\"", "_");
}
}
}

0 comments on commit 3e9dea4

Please sign in to comment.