Project model cleanup

- Use ProjectResolver in the ProjectDependencyProvider
- Remove environment variable reading in the project reader and moved it to dotnet-pack
This commit is contained in:
David Fowler 2016-01-03 08:18:25 -08:00
parent 4b07b2d034
commit 5dbb7ab44d
6 changed files with 15 additions and 40 deletions

View file

@ -172,7 +172,7 @@ namespace Microsoft.DotNet.ProjectModel
} }
var libraries = new Dictionary<LibraryKey, LibraryDescription>(); var libraries = new Dictionary<LibraryKey, LibraryDescription>();
var projectResolver = new ProjectDependencyProvider(Settings); var projectResolver = new ProjectDependencyProvider(ProjectResolver);
var mainProject = projectResolver.GetDescription(TargetFramework, Project); var mainProject = projectResolver.GetDescription(TargetFramework, Project);
@ -382,10 +382,11 @@ namespace Microsoft.DotNet.ProjectModel
return null; return null;
} }
private static Project ResolveProject(string projectDirectory) private Project ResolveProject(string projectDirectory)
{ {
// TODO: Handle diagnostics
Project project; Project project;
if (ProjectReader.TryGetProject(projectDirectory, out project)) if (ProjectReader.TryGetProject(projectDirectory, out project, diagnostics: null, settings: Settings))
{ {
return project; return project;
} }

View file

@ -102,7 +102,7 @@ namespace Microsoft.DotNet.ProjectModel
{ {
try try
{ {
var buildVersion = settings.VersionSuffix ?? Environment.GetEnvironmentVariable("DOTNET_BUILD_VERSION"); var buildVersion = settings.VersionSuffix;
project.Version = SpecifySnapshot(version, buildVersion); project.Version = SpecifySnapshot(version, buildVersion);
} }
catch (Exception ex) catch (Exception ex)
@ -111,7 +111,7 @@ namespace Microsoft.DotNet.ProjectModel
} }
} }
var fileVersion = Environment.GetEnvironmentVariable("DOTNET_ASSEMBLY_FILE_VERSION"); var fileVersion = settings.AssemblyFileVersion;
if (string.IsNullOrWhiteSpace(fileVersion)) if (string.IsNullOrWhiteSpace(fileVersion))
{ {
project.AssemblyFileVersion = project.Version.Version; project.AssemblyFileVersion = project.Version.Version;

View file

@ -1,12 +1,8 @@
using System; namespace Microsoft.DotNet.ProjectModel
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Microsoft.DotNet.ProjectModel
{ {
public class ProjectReaderSettings public class ProjectReaderSettings
{ {
public string VersionSuffix = null; public string VersionSuffix { get; set; }
public string AssemblyFileVersion { get; set; }
} }
} }

View file

@ -7,7 +7,6 @@ using System.IO;
using System.Linq; using System.Linq;
using Microsoft.DotNet.ProjectModel.Graph; using Microsoft.DotNet.ProjectModel.Graph;
using NuGet.Packaging; using NuGet.Packaging;
using NuGet.Versioning;
namespace Microsoft.DotNet.ProjectModel.Resolution namespace Microsoft.DotNet.ProjectModel.Resolution
{ {

View file

@ -5,9 +5,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Runtime.Versioning;
using Microsoft.DotNet.ProjectModel.Graph; using Microsoft.DotNet.ProjectModel.Graph;
using NuGet;
using NuGet.Frameworks; using NuGet.Frameworks;
namespace Microsoft.DotNet.ProjectModel.Resolution namespace Microsoft.DotNet.ProjectModel.Resolution
@ -15,18 +13,10 @@ namespace Microsoft.DotNet.ProjectModel.Resolution
public class ProjectDependencyProvider public class ProjectDependencyProvider
{ {
private Func<string, Project> _resolveProject; private Func<string, Project> _resolveProject;
private ProjectReaderSettings _settings;
public ProjectDependencyProvider(ProjectReaderSettings settings = null) public ProjectDependencyProvider(Func<string, Project> projectCacheResolver)
{
_resolveProject = ResolveProject;
_settings = settings;
}
public ProjectDependencyProvider(Func<string, Project> projectCacheResolver, ProjectReaderSettings settings = null)
{ {
_resolveProject = projectCacheResolver; _resolveProject = projectCacheResolver;
_settings = settings;
} }
public ProjectDescription GetDescription(string name, public ProjectDescription GetDescription(string name,
@ -86,18 +76,5 @@ namespace Microsoft.DotNet.ProjectModel.Resolution
targetFrameworkInfo, targetFrameworkInfo,
!unresolved); !unresolved);
} }
private Project ResolveProject(string path)
{
Project project;
if (ProjectReader.TryGetProject(path, out project, settings: _settings))
{
return project;
}
else
{
return null;
}
}
} }
} }

View file

@ -9,7 +9,6 @@ using System.Text;
using Microsoft.DotNet.ProjectModel; using Microsoft.DotNet.ProjectModel;
using Microsoft.Dnx.Runtime.Common.CommandLine; using Microsoft.Dnx.Runtime.Common.CommandLine;
using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.Cli.Compiler.Common;
namespace Microsoft.DotNet.Tools.Compiler namespace Microsoft.DotNet.Tools.Compiler
{ {
@ -51,10 +50,13 @@ namespace Microsoft.DotNet.Tools.Compiler
return 1; return 1;
} }
ProjectReaderSettings settings = null; // Set defaults based on the environment
var settings = new ProjectReaderSettings();
settings.VersionSuffix = Environment.GetEnvironmentVariable("DOTNET_BUILD_VERSION");
settings.AssemblyFileVersion = Environment.GetEnvironmentVariable("DOTNET_ASSEMBLY_FILE_VERSION");
if (versionSuffix.HasValue()) if (versionSuffix.HasValue())
{ {
settings = new ProjectReaderSettings();
settings.VersionSuffix = versionSuffix.Value(); settings.VersionSuffix = versionSuffix.Value();
} }