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

Adds fallback folder for full framework and multi-tfm projects. #1399

Closed
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<!--
***********************************************************************************************
Microsoft.NET.NuGetOfflineCache.targets

WARNING: DO NOT MODIFY this file unless you are knowledgeable about MSBuild and have
created a backup copy. Incorrect changes to this file will make it
impossible to load or build your projects from the command-line or the IDE.

Copyright (c) .NET Foundation. All rights reserved.
***********************************************************************************************
-->
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
</PropertyGroup>

<PropertyGroup>
<_NugetFallbackFolder>$(MSBuildThisFileDirectory)..\..\..\..\NuGetFallbackFolder</_NugetFallbackFolder>
</PropertyGroup>

<Target Name="_SetIsNETCoreOrNETStandard1x"
Returns="$(_IsNETCoreOrNETStandard1x)">
<PropertyGroup>
<_IsNETCoreOrNETStandard1x Condition=" '$(_IsNETCoreOrNETStandard)' == 'true' and '$(_TargetFrameworkVersionWithoutV)' &lt; '2.0' ">true</_IsNETCoreOrNETStandard1x>
</PropertyGroup>
</Target>

<Target Name="_SetNuGetSDKOfflineCache"
DependsOnTargets="_SetIsNETCoreOrNETStandard1x"
BeforeTargets="_GetRestoreSettings">
<PropertyGroup Condition=" '$(DisableImplicitNuGetFallbackFolder)' != 'true' and Exists($(_NugetFallbackFolder)) ">
<RestoreAdditionalProjectSources Condition=" '$(_IsNETCoreOrNETStandard1x)' == 'true' ">$(RestoreAdditionalProjectSources);$(_NugetFallbackFolder)</RestoreAdditionalProjectSources>

<RestoreAdditionalProjectFallbackFolders Condition=" '$(_IsNETCoreOrNETStandard1x)' != 'true' ">$(RestoreAdditionalProjectFallbackFolders);$(_NugetFallbackFolder)</RestoreAdditionalProjectFallbackFolders>
</PropertyGroup>
</Target>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ Copyright (c) .NET Foundation. All rights reserved.
<PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
<_IsExecutable Condition="'$(OutputType)' == 'Exe' or '$(OutputType)'=='WinExe'">true</_IsExecutable>
<_NugetFallbackFolder>$(MSBuildThisFileDirectory)..\..\..\..\NuGetFallbackFolder</_NugetFallbackFolder>
</PropertyGroup>

<PropertyGroup Condition="'$(HasRuntimeOutput)' == ''">
Expand Down Expand Up @@ -88,11 +87,11 @@ Copyright (c) .NET Foundation. All rights reserved.
<_TargetFrameworkVersionWithoutV Condition="$(TargetFrameworkVersion.StartsWith('v'))">$(TargetFrameworkVersion.Substring(1))</_TargetFrameworkVersionWithoutV>
</PropertyGroup>

<PropertyGroup Condition=" '$(DisableImplicitNuGetFallbackFolder)' != 'true' and '$(_IsNETCoreOrNETStandard)' == 'true' and Exists($(_NugetFallbackFolder)) ">
<RestoreAdditionalProjectSources Condition=" '$(_TargetFrameworkVersionWithoutV)' &lt; '2.0' ">$(RestoreAdditionalProjectSources);$(_NugetFallbackFolder)</RestoreAdditionalProjectSources>

<RestoreAdditionalProjectFallbackFolders Condition=" '$(_TargetFrameworkVersionWithoutV)' >= '2.0' ">$(RestoreAdditionalProjectFallbackFolders);$(_NugetFallbackFolder)</RestoreAdditionalProjectFallbackFolders>
</PropertyGroup>
<!--
Sets RestoreAdditionalProjectSources or RestoreAdditionalProjectFallbackFolders to the SDK Offline Cache based
on the TargetFramework.
-->
<Import Project="$(MSBuildThisFileDirectory)Microsoft.NET.NuGetOfflineCache.targets" />

<ItemGroup Condition=" '$(DisableImplicitFrameworkReferences)' != 'true' and '$(TargetFrameworkIdentifier)' == '.NETFramework'">

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Copyright (c) .NET Foundation. All rights reserved.
</PropertyGroup>

<Import Project="..\build\Microsoft.NET.Sdk.Common.targets"/>
<Import Project="..\build\Microsoft.NET.NuGetOfflineCache.targets"/>

<!--
============================================================
Expand All @@ -31,6 +32,22 @@ Copyright (c) .NET Foundation. All rights reserved.
<Error Text="The 'Publish' target is not supported without specifying a target framework. The current project targets multiple frameworks, please specify the framework for the published application." />
</Target>

<Target Name="_SetIsNETCoreOrNETStandard1x">
<ItemGroup>
<_SetIsNETCoreOrNETStandard1xTargetFrameworks Include="$(TargetFrameworks)" />
</ItemGroup>

<MSBuild Projects="$(MSBuildProjectFile)"
Targets="_SetIsNETCoreOrNETStandard1x"
Properties="TargetFramework=%(_SetIsNETCoreOrNETStandard1xTargetFrameworks.Identity)">
<Output ItemName="_AllIsNETCoreOrNETStandard1x" TaskParameter="TargetOutputs" />
</MSBuild>

<PropertyGroup>
<_IsNETCoreOrNETStandard1x Condition=" '%(_AllIsNETCoreOrNETStandard1x.Identity)' == 'true' ">true</_IsNETCoreOrNETStandard1x>
</PropertyGroup>
</Target>

<!--
============================================================
GetAllRuntimeIdentifiers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,18 @@ public GivenThatWeWantToRestoreProjectsUsingNuGetConfigProperties(ITestOutputHel
[InlineData("netstandard1.3", "1.3", true)]
[InlineData("netcoreapp1.0", "1.0", true)]
[InlineData("netcoreapp1.1", "1.1", true)]
[InlineData("netcoreapp1.0;netcoreapp2.0", "multiTFM1020app", true)]
[InlineData("netstandard2.0", "2.0", false)]
[InlineData("netcoreapp2.0", "2.0app", false)]
[InlineData("net461", "461app", false)]
[InlineData("netcoreapp2.0;net461", "multiTFM20app", false)]
public void I_can_restore_a_project_with_implicit_msbuild_nuget_config(
string framework,
string frameworks,
string projectPrefix,
bool fileExists)
{
string testProjectName = $"{projectPrefix}Fallback";
TestAsset testProjectTestAsset = CreateTestAsset(testProjectName, framework);
TestAsset testProjectTestAsset = CreateTestAsset(testProjectName, frameworks);

var packagesFolder = Path.Combine(RepoInfo.TestsFolder, "packages", testProjectName);

Expand All @@ -56,24 +59,24 @@ public void I_can_restore_a_project_with_implicit_msbuild_nuget_config(
[InlineData("netcoreapp1.1", "1.1")]
[InlineData("netstandard2.0", "2.0")]
[InlineData("netcoreapp2.0", "2.0app")]
public void I_can_disable_implicit_msbuild_nuget_config(string framework, string projectPrefix)
public void I_can_disable_implicit_msbuild_nuget_config(string frameworks, string projectPrefix)
{
string testProjectName = $"{projectPrefix}DisabledFallback";
TestAsset testProjectTestAsset = CreateTestAsset(testProjectName, framework);
TestAsset testProjectTestAsset = CreateTestAsset(testProjectName, frameworks);

var restoreCommand = testProjectTestAsset.GetRestoreCommand(Log, relativePath: testProjectName);
restoreCommand.Execute($"/p:DisableImplicitNuGetFallbackFolder=true").Should().Fail();
}

private TestAsset CreateTestAsset(string testProjectName, string framework)
private TestAsset CreateTestAsset(string testProjectName, string frameworks)
{
var packageInNuGetFallbackFolder = CreatePackageInNuGetFallbackFolder();

var testProject =
new TestProject
{
Name = testProjectName,
TargetFrameworks = framework,
TargetFrameworks = frameworks,
IsSdkProject = true
};

Expand Down