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

Import common targets if LanguageTargets property isn't set. #539

Merged
merged 1 commit into from
Dec 28, 2016
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
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