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

Rename OutputType to ProjectStyle #1067

Closed
wants to merge 5 commits into from
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
Expand Up @@ -532,11 +532,11 @@ private void AddInputsFromDependencyGraphSpec(PackageRestoreInputs packageRestor
.Select(GetPackagesConfigFile)
.Where(path => path != null));

// NETCore or UAP
// Filter down to just the requested projects in the file
// that support transitive references.
var v3RestoreProjects = dgFileOutput.Projects
.Where(project => (project.RestoreMetadata.OutputType == RestoreOutputType.NETCore
|| project.RestoreMetadata.OutputType == RestoreOutputType.UAP)
.Where(project => (project.RestoreMetadata.ProjectStyle == ProjectStyle.PackageReference
|| project.RestoreMetadata.ProjectStyle == ProjectStyle.ProjectJson)
&& entryPointProjects.Contains(project));

packageRestoreInputs.RestoreV3Context.Inputs.AddRange(v3RestoreProjects
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ private static PackageSpec ToPackageSpec(ProjectNames projectNames, IVsProjectRe
Path.Combine(
projectDirectory,
projectRestoreInfo.BaseIntermediatePath)),
OutputType = RestoreOutputType.NETCore,
ProjectStyle = ProjectStyle.PackageReference,
TargetFrameworks = projectRestoreInfo.TargetFrameworks
.Cast<IVsTargetFrameworkInfo>()
.Select(item => ToProjectRestoreMetadataFrameworkInfo(item, projectDirectory))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ private PackageSpec GetPackageSpec()
RuntimeGraph = runtimeGraph,
RestoreMetadata = new ProjectRestoreMetadata
{
OutputType = RestoreOutputType.NETCore,
ProjectStyle = ProjectStyle.PackageReference,
OutputPath = GetBaseIntermediatePath(),
ProjectPath = _projectFullPath,
ProjectName = _projectName ?? _projectUniqueName,
Expand Down
12 changes: 6 additions & 6 deletions src/NuGet.Core/NuGet.Build.Tasks/BuildTasksUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static void AddAllProjectsForRestore(DependencyGraphSpec spec)
{
// Add everything from projects except for packages.config and unknown project types
foreach (var project in spec.Projects
.Where(project => RestorableTypes.Contains(project.RestoreMetadata.OutputType)))
.Where(project => RestorableTypes.Contains(project.RestoreMetadata.ProjectStyle)))
{
spec.AddRestore(project.RestoreMetadata.ProjectUniqueName);
}
Expand Down Expand Up @@ -51,12 +51,12 @@ public static void AddPropertyIfExists(IDictionary<string, string> properties, s
}
}

private static HashSet<RestoreOutputType> RestorableTypes = new HashSet<RestoreOutputType>()
private static HashSet<ProjectStyle> RestorableTypes = new HashSet<ProjectStyle>()
{
RestoreOutputType.DotnetCliTool,
RestoreOutputType.NETCore,
RestoreOutputType.Standalone,
RestoreOutputType.UAP
ProjectStyle.DotnetCliTool,
ProjectStyle.PackageReference,
ProjectStyle.Standalone,
ProjectStyle.ProjectJson
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public override bool Execute()
BuildTasksUtility.AddPropertyIfExists(properties, "FallbackFolders", RestoreFallbackFolders);
BuildTasksUtility.AddPropertyIfExists(properties, "PackagesPath", RestorePackagesPath);
properties.Add("TargetFrameworks", ToolFramework);
properties.Add("OutputType", RestoreOutputType.DotnetCliTool.ToString());
properties.Add("ProjectStyle", ProjectStyle.DotnetCliTool.ToString());
BuildTasksUtility.CopyPropertyIfExists(msbuildItem, properties, "Version");

entries.Add(new TaskItem(Guid.NewGuid().ToString(), properties));
Expand Down
76 changes: 41 additions & 35 deletions src/NuGet.Core/NuGet.Build.Tasks/NuGet.targets
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,13 @@ Copyright (c) .NET Foundation. All rights reserved.
============================================================
-->
<Target Name="_GenerateRestoreSpecs"
DependsOnTargets="_GetProjectRestoreType"
DependsOnTargets="_GetRestoreProjectStyle"
Returns="@(_RestoreGraphEntry)">
<Message Text="Restore entry point $(MSBuildProjectFullPath)" Importance="low" />

<!-- Mark entry point -->
<ItemGroup Condition=" '$(RestoreProjects)' == '' OR '$(RestoreProjects)' == 'true' ">
<_RestoreGraphEntry Include="$([System.Guid]::NewGuid())" Condition=" '$(_ProjectRestoreType)' != 'Unknown' ">
<_RestoreGraphEntry Include="$([System.Guid]::NewGuid())" Condition=" '$(RestoreProjectStyle)' != 'Unknown' ">
<Type>RestoreSpec</Type>
<ProjectUniqueName>$(MSBuildProjectFullPath)</ProjectUniqueName>
</_RestoreGraphEntry>
Expand Down Expand Up @@ -240,26 +240,33 @@ Copyright (c) .NET Foundation. All rights reserved.
<Target Name="_GetProjectJsonPath"
Returns="$(_CurrentProjectJsonPath)">
<!-- Get project.json path -->
<GetRestoreProjectJsonPathTask ProjectPath="$(MSBuildProjectFullPath)">
<!-- Skip this if the project style is already set. -->
<GetRestoreProjectJsonPathTask
ProjectPath="$(MSBuildProjectFullPath)"
Condition=" '$(RestoreProjectStyle)' == 'ProjectJson' OR '$(RestoreProjectStyle)' == '' ">
<Output TaskParameter="ProjectJsonPath" PropertyName="_CurrentProjectJsonPath" />
</GetRestoreProjectJsonPathTask>
</Target>

<!--
============================================================
_GetProjectRestoreType
_GetRestoreProjectStyle
Determine the project restore type.
============================================================
-->
<Target Name="_GetProjectRestoreType"
<Target Name="_GetRestoreProjectStyle"
DependsOnTargets="_GetProjectJsonPath"
Returns="$(_ProjectRestoreType)">
<!-- Check for project.json and NETCore properties -->
Returns="$(RestoreProjectStyle)">
<!-- This may be overridden by setting RestoreProjectStyle in the project. -->
<PropertyGroup>
<_ProjectRestoreType>Unknown</_ProjectRestoreType>
<_ProjectRestoreType Condition=" '$(_CurrentProjectJsonPath)' != '' ">UAP</_ProjectRestoreType>
<_ProjectRestoreType Condition=" '$(TargetFrameworks)' != '' ">NETCore</_ProjectRestoreType>
<_ProjectRestoreType Condition=" '$(TargetFramework)' != '' AND @(PackageReference) != '' ">NETCore</_ProjectRestoreType>
<!-- .NETCore cross platform projects contain the TargetFrameworks property and must be treated as PackageReference. -->
<RestoreProjectStyle Condition=" '$(RestoreProjectStyle)' == '' AND '$(TargetFrameworks)' != '' ">PackageReference</RestoreProjectStyle>
<!-- If any PackageReferences exist treat it as PackageReference. This has priority over project.json. -->
<RestoreProjectStyle Condition=" '$(RestoreProjectStyle)' == '' AND @(PackageReference) != '' ">PackageReference</RestoreProjectStyle>
<!-- If this is not a PackageReference project check if project.json or projectName.project.json exists. -->
<RestoreProjectStyle Condition=" '$(RestoreProjectStyle)' == '' AND '$(_CurrentProjectJsonPath)' != '' ">ProjectJson</RestoreProjectStyle>
<!-- This project is either a packages.config project or one that does not use NuGet at all. -->
<RestoreProjectStyle Condition=" '$(RestoreProjectStyle)' == '' ">Unknown</RestoreProjectStyle>
</PropertyGroup>
</Target>

Expand All @@ -270,17 +277,17 @@ Copyright (c) .NET Foundation. All rights reserved.
============================================================
-->
<Target Name="_GetRestoreTargetFrameworksOutput"
DependsOnTargets="_GetProjectRestoreType"
DependsOnTargets="_GetRestoreProjectStyle"
Returns="@(_RestoreTargetFrameworksOutputFiltered)">

<!-- Loop on target frameworks, if no frameworks exist the targets below will
run once using an empty framework string -->
<ItemGroup Condition=" '$(_ProjectRestoreType)' == 'NETCore' AND '$(TargetFrameworks)' != '' ">
<ItemGroup Condition=" '$(RestoreProjectStyle)' == 'PackageReference' AND '$(TargetFrameworks)' != '' ">
<_RestoreTargetFrameworksOutput Include="$(TargetFrameworks.Split(';'))" />
</ItemGroup>

<!-- Use $(TargetFramework) if $(TargetFrameworks) is empty -->
<ItemGroup Condition=" '$(_ProjectRestoreType)' == 'NETCore' AND '$(TargetFrameworks)' == '' AND '$(TargetFramework)' != '' ">
<ItemGroup Condition=" '$(RestoreProjectStyle)' == 'PackageReference' AND '$(TargetFrameworks)' == '' AND '$(TargetFramework)' != '' ">
<_RestoreTargetFrameworksOutput Include="$(TargetFramework)" />
</ItemGroup>

Expand All @@ -300,15 +307,15 @@ Copyright (c) .NET Foundation. All rights reserved.
============================================================
-->
<Target Name="_GenerateRestoreProjectSpec"
DependsOnTargets="_GetProjectRestoreType;_GetRestoreTargetFrameworksOutput"
DependsOnTargets="_GetRestoreProjectStyle;_GetRestoreTargetFrameworksOutput"
Returns="@(_RestoreGraphEntry)">

<!-- Determine the restore output path -->
<PropertyGroup Condition=" '$(_ProjectRestoreType)' == 'NETCore' ">
<PropertyGroup Condition=" '$(RestoreProjectStyle)' == 'PackageReference' ">
<RestoreOutputPath Condition=" '$(RestoreOutputPath)' == '' " >$(BaseIntermediateOutputPath)</RestoreOutputPath>
</PropertyGroup>

<ConvertToAbsolutePath Paths="$(RestoreOutputPath)" Condition=" '$(_ProjectRestoreType)' == 'NETCore' ">
<ConvertToAbsolutePath Paths="$(RestoreOutputPath)" Condition=" '$(RestoreProjectStyle)' == 'PackageReference' ">
<Output TaskParameter="AbsolutePaths" PropertyName="RestoreOutputAbsolutePath" />
</ConvertToAbsolutePath>

Expand All @@ -322,8 +329,8 @@ Copyright (c) .NET Foundation. All rights reserved.
-->
<PropertyGroup>
<_RestoreProjectName>$(MSBuildProjectName)</_RestoreProjectName>
<_RestoreProjectName Condition=" '$(_ProjectRestoreType)' == 'NETCore' AND '$(AssemblyName)' != '' ">$(AssemblyName)</_RestoreProjectName>
<_RestoreProjectName Condition=" '$(_ProjectRestoreType)' == 'NETCore' AND '$(PackageId)' != '' ">$(PackageId)</_RestoreProjectName>
<_RestoreProjectName Condition=" '$(RestoreProjectStyle)' == 'PackageReference' AND '$(AssemblyName)' != '' ">$(AssemblyName)</_RestoreProjectName>
<_RestoreProjectName Condition=" '$(RestoreProjectStyle)' == 'PackageReference' AND '$(PackageId)' != '' ">$(PackageId)</_RestoreProjectName>
</PropertyGroup>

<!--
Expand All @@ -332,19 +339,19 @@ Copyright (c) .NET Foundation. All rights reserved.
Use Version if it exists
Override with PackageVersion if it exists (same as pack)
-->
<PropertyGroup Condition=" '$(_ProjectRestoreType)' == 'NETCore' ">
<PropertyGroup Condition=" '$(RestoreProjectStyle)' == 'PackageReference' ">
<_RestoreProjectVersion>1.0.0</_RestoreProjectVersion>
<_RestoreProjectVersion Condition=" '$(Version)' != '' ">$(Version)</_RestoreProjectVersion>
<_RestoreProjectVersion Condition=" '$(PackageVersion)' != '' ">$(PackageVersion)</_RestoreProjectVersion>
</PropertyGroup>

<!-- Determine if this will use cross targeting -->
<PropertyGroup Condition=" '$(_ProjectRestoreType)' == 'NETCore' AND '$(TargetFrameworks)' != '' ">
<PropertyGroup Condition=" '$(RestoreProjectStyle)' == 'PackageReference' AND '$(TargetFrameworks)' != '' ">
<_RestoreCrossTargeting>true</_RestoreCrossTargeting>
</PropertyGroup>

<!-- Write properties for the top level entry point -->
<ItemGroup Condition=" '$(_ProjectRestoreType)' == 'NETCore' ">
<ItemGroup Condition=" '$(RestoreProjectStyle)' == 'PackageReference' ">
<_RestoreGraphEntry Include="$([System.Guid]::NewGuid())">
<Type>ProjectSpec</Type>
<Version>$(_RestoreProjectVersion)</Version>
Expand All @@ -354,8 +361,7 @@ Copyright (c) .NET Foundation. All rights reserved.
<Sources>$(RestoreSources)</Sources>
<FallbackFolders>$(RestoreFallbackFolders)</FallbackFolders>
<PackagesPath>$(RestorePackagesPath)</PackagesPath>
<FallbackFolders>$(RestoreFallbackFolders)</FallbackFolders>
<OutputType>$(_ProjectRestoreType)</OutputType>
<ProjectStyle>$(RestoreProjectStyle)</ProjectStyle>
<OutputPath>$(RestoreOutputAbsolutePath)</OutputPath>
<TargetFrameworks>@(_RestoreTargetFrameworksOutputFiltered)</TargetFrameworks>
<RuntimeIdentifiers>$(RuntimeIdentifiers);$(RuntimeIdentifier)</RuntimeIdentifiers>
Expand All @@ -366,7 +372,7 @@ Copyright (c) .NET Foundation. All rights reserved.
</ItemGroup>

<!-- Use project.json -->
<ItemGroup Condition=" '$(_ProjectRestoreType)' == 'UAP' ">
<ItemGroup Condition=" '$(RestoreProjectStyle)' == 'ProjectJson' ">
<_RestoreGraphEntry Include="$([System.Guid]::NewGuid())">
<Type>ProjectSpec</Type>
<ProjectUniqueName>$(MSBuildProjectFullPath)</ProjectUniqueName>
Expand All @@ -377,18 +383,18 @@ Copyright (c) .NET Foundation. All rights reserved.
<PackagesPath>$(RestorePackagesPath)</PackagesPath>
<FallbackFolders>$(RestoreFallbackFolders)</FallbackFolders>
<ProjectJsonPath>$(_CurrentProjectJsonPath)</ProjectJsonPath>
<OutputType>$(_ProjectRestoreType)</OutputType>
<ProjectStyle>$(RestoreProjectStyle)</ProjectStyle>
</_RestoreGraphEntry>
</ItemGroup>

<!-- Non-NuGet type -->
<ItemGroup Condition=" '$(_ProjectRestoreType)' == 'Unknown' ">
<ItemGroup Condition=" '$(RestoreProjectStyle)' == 'Unknown' ">
<_RestoreGraphEntry Include="$([System.Guid]::NewGuid())">
<Type>ProjectSpec</Type>
<ProjectUniqueName>$(MSBuildProjectFullPath)</ProjectUniqueName>
<ProjectPath>$(MSBuildProjectFullPath)</ProjectPath>
<ProjectName>$(_RestoreProjectName)</ProjectName>
<OutputType>$(_ProjectRestoreType)</OutputType>
<ProjectStyle>$(RestoreProjectStyle)</ProjectStyle>
<TargetFrameworks>$(TargetFrameworkMoniker)</TargetFrameworks>
</_RestoreGraphEntry>
</ItemGroup>
Expand All @@ -401,7 +407,7 @@ Copyright (c) .NET Foundation. All rights reserved.
============================================================
-->
<Target Name="_GenerateRestoreDependencies"
DependsOnTargets="_GetProjectRestoreType;_GetRestoreTargetFrameworksOutput"
DependsOnTargets="_GetRestoreProjectStyle;_GetRestoreTargetFrameworksOutput"
Returns="@(_RestoreGraphEntry)">

<!-- Get project and package references -->
Expand Down Expand Up @@ -429,7 +435,7 @@ Copyright (c) .NET Foundation. All rights reserved.
============================================================
-->
<Target Name="_GetAllRestoreProjectReferences"
DependsOnTargets="_GetProjectRestoreType;_GetRestoreTargetFrameworksOutput"
DependsOnTargets="_GetRestoreProjectStyle;_GetRestoreTargetFrameworksOutput"
Returns="@(RestoreGraphProjectFullPathForOutput)">

<!-- Get complete set of project references -->
Expand Down Expand Up @@ -458,7 +464,7 @@ Copyright (c) .NET Foundation. All rights reserved.
============================================================
-->
<Target Name="_GetChildRestoreProjects"
DependsOnTargets="_GetProjectRestoreType;_GetAllRestoreProjectReferences"
DependsOnTargets="_GetRestoreProjectStyle;_GetAllRestoreProjectReferences"
Returns="@(_RestoreGraphEntry)">

<!-- Recurse into referenced projects -->
Expand Down Expand Up @@ -487,7 +493,7 @@ Copyright (c) .NET Foundation. All rights reserved.
-->
<Target Name="_GenerateRestoreGraphWalk"
DependsOnTargets="
_GetProjectRestoreType;
_GetRestoreProjectStyle;
_GetRestoreTargetFrameworksOutput;
_GenerateRestoreProjectSpec;
_GenerateRestoreDependencies;
Expand All @@ -504,7 +510,7 @@ Copyright (c) .NET Foundation. All rights reserved.
============================================================
-->
<Target Name="_GenerateRestoreGraphWalkPerFramework"
DependsOnTargets="_GenerateRestoreProjectReferencePaths;_GetProjectRestoreType"
DependsOnTargets="_GenerateRestoreProjectReferencePaths;_GetRestoreProjectStyle"
Returns="@(_RestoreGraphEntry)">

<!-- Write out project references -->
Expand All @@ -520,7 +526,7 @@ Copyright (c) .NET Foundation. All rights reserved.

<!-- Write out package references for NETCore -->
<GetRestorePackageReferencesTask
Condition=" '$(_ProjectRestoreType)' == 'NETCore' "
Condition=" '$(RestoreProjectStyle)' == 'PackageReference' "
ProjectUniqueName="$(MSBuildProjectFullPath)"
PackageReferences="@(PackageReference)"
TargetFrameworks="$(TargetFramework)">
Expand All @@ -531,7 +537,7 @@ Copyright (c) .NET Foundation. All rights reserved.
</GetRestorePackageReferencesTask>

<!-- Write out target framework information -->
<ItemGroup Condition=" '$(_ProjectRestoreType)' == 'NETCore' AND '$(PackageTargetFallback)' != '' ">
<ItemGroup Condition=" '$(RestoreProjectStyle)' == 'PackageReference' AND '$(PackageTargetFallback)' != '' ">
<_RestoreGraphEntry Include="$([System.Guid]::NewGuid())">
<Type>TargetFrameworkInformation</Type>
<ProjectUniqueName>$(MSBuildProjectFullPath)</ProjectUniqueName>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public LockFile CreateLockFile(

var previousLibraries = previousLockFile?.Libraries.ToDictionary(l => Tuple.Create(l.Name, l.Version));

if (project.RestoreMetadata?.OutputType == RestoreOutputType.NETCore)
if (project.RestoreMetadata?.ProjectStyle == ProjectStyle.PackageReference)
{
AddProjectFileDependenciesForNETCore(project, lockFile, targetGraphs);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ private IReadOnlyList<RestoreSummaryRequest> GetRequestsFromItems(RestoreArgs re

var request = Create(rootProject, externalClosure, restoreContext, settingsOverride: _providerSettingsOverride);

if (request.Request.RestoreOutputType == RestoreOutputType.DotnetCliTool)
if (request.Request.ProjectStyle == ProjectStyle.DotnetCliTool)
{
// Store tool requests to be filtered later
toolRequests.Add(request);
Expand Down Expand Up @@ -112,17 +112,17 @@ private static ExternalProjectReference GetExternalProject(PackageSpec rootProje
var projectReferences = rootProject.RestoreMetadata?.TargetFrameworks.SelectMany(e => e.ProjectReferences)
?? new List<ProjectRestoreReference>();

var type = rootProject.RestoreMetadata?.OutputType ?? RestoreOutputType.Unknown;
var type = rootProject.RestoreMetadata?.ProjectStyle ?? ProjectStyle.Unknown;

// Leave the spec null for non-nuget projects.
// In the future additional P2P TFM checking could be handled by
// creating a spec for non-NuGet projects and including the TFM.
PackageSpec projectSpec = null;

if (type == RestoreOutputType.NETCore
|| type == RestoreOutputType.UAP
|| type == RestoreOutputType.DotnetCliTool
|| type == RestoreOutputType.Standalone)
if (type == ProjectStyle.PackageReference
|| type == ProjectStyle.ProjectJson
|| type == ProjectStyle.DotnetCliTool
|| type == ProjectStyle.Standalone)
{
projectSpec = rootProject;
}
Expand Down Expand Up @@ -174,7 +174,7 @@ private RestoreSummaryRequest Create(
restoreContext.Log);

// Set properties from the restore metadata
request.RestoreOutputType = project.PackageSpec?.RestoreMetadata?.OutputType ?? RestoreOutputType.Unknown;
request.ProjectStyle = project.PackageSpec?.RestoreMetadata?.ProjectStyle ?? ProjectStyle.Unknown;
request.RestoreOutputPath = project.PackageSpec?.RestoreMetadata?.OutputPath ?? rootPath;
var restoreLegacyPackagesDirectory = project.PackageSpec?.RestoreMetadata?.LegacyPackagesDirectory
?? DefaultRestoreLegacyPackagesDirectory;
Expand Down
Loading