Skip to content

Commit

Permalink
Import common targets if LanguageTargets property isn't set.
Browse files Browse the repository at this point in the history
This will allow restore to succeed.  Fixes dotnet#448
  • Loading branch information
dsplaisted committed Dec 20, 2016
1 parent dceed2b commit 3172d59
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
9 changes: 6 additions & 3 deletions src/Tasks/Microsoft.NET.Build.Tasks/sdk/Sdk.targets
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,13 @@ Copyright (c) .NET Foundation. All rights reserved.
<PropertyGroup Condition="'$(LanguageTargets)' == ''">
<LanguageTargets Condition="'$(MSBuildProjectExtension)' == '.csproj'">$(MSBuildToolsPath)\Microsoft.CSharp.targets</LanguageTargets>
<LanguageTargets Condition="'$(MSBuildProjectExtension)' == '.vbproj'">$(MSBuildToolsPath)\Microsoft.VisualBasic.targets</LanguageTargets>

<!-- If LanguageTargets isn't otherwise set, then just import the common targets. This should allow the restore target to run,
which could bring in NuGet packages that set the LanguageTargets to something else. This means support for different
languages could either be supplied via an SDK or via a NuGet package. -->
<LanguageTargets Condition="'$(LanguageTargets)' == ''">$(MSBuildToolsPath)\Microsoft.Common.CurrentVersion.targets</LanguageTargets>
</PropertyGroup>

<!-- TODO: Generate error if LanguageTargets property isn't set here. This would happen, for example if an .fsproj referenced the .NET Sdk
but not the FSharp one. See https://github.com/dotnet/sdk/issues/448 -->

<!-- REMARK: Dont remove/rename, the LanguageTargets property is used by F# to hook inside the project's sdk
using Sdk attribute (from .NET Core Sdk 1.0.0-preview4) -->
<Import Project="$(LanguageTargets)"/>
Expand Down
22 changes: 22 additions & 0 deletions test/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildALibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,28 @@ public void The_build_fails_if_nuget_restore_has_not_occurred()
.Fail();
}

[Fact]
public void Restore_succeeds_even_if_the_project_extension_is_for_a_different_language()
{
var testAsset = _testAssetsManager
.CopyTestAsset("AppWithLibrary")
.WithSource();

var libraryProjectDirectory = Path.Combine(testAsset.TestRoot, "TestLibrary");

var oldProjectFile = Path.Combine(libraryProjectDirectory, "TestLibrary.csproj");
var newProjectFile = Path.Combine(libraryProjectDirectory, "TestLibrary.fsproj");

File.Move(oldProjectFile, newProjectFile);

var restoreCommand = new RestoreCommand(Stage0MSBuild, libraryProjectDirectory, "TestLibrary.fsproj");

restoreCommand
.Execute()
.Should()
.Pass();
}

[Theory]
[InlineData(".NETStandard,Version=v1.0", new[] { "NETSTANDARD1_0" }, false)]
[InlineData("netstandard1.3", new[] { "NETSTANDARD1_3" }, false)]
Expand Down
4 changes: 2 additions & 2 deletions test/Microsoft.NET.TestFramework/Commands/RestoreCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public sealed class RestoreCommand : TestCommand
private List<string> _sources = new List<string>();
private bool _captureStdOut;

public RestoreCommand(MSBuildTest msbuild, string projectPath)
: base(msbuild, projectPath)
public RestoreCommand(MSBuildTest msbuild, string projectPath, string relativePathToProject = null)
: base(msbuild, projectPath, relativePathToProject)
{
}

Expand Down

0 comments on commit 3172d59

Please sign in to comment.