Merge branch 'troy/xp' into rel/1.0.0

This commit is contained in:
Troy Dai 2016-03-31 17:16:41 -07:00
commit 9f23b7adf5
7 changed files with 70 additions and 30 deletions

View file

@ -141,7 +141,7 @@ namespace Microsoft.DotNet.Cli.Utils
try
{
lockFile = LockFileReader.Read(lockFilePath);
lockFile = LockFileReader.Read(lockFilePath, designTime: false);
}
catch (FileFormatException ex)
{

View file

@ -22,10 +22,9 @@ namespace Microsoft.DotNet.ProjectModel.Graph
_msbuildTargetLibraries = msbuildProjectLibraries.ToDictionary(GetProjectLibraryKey, l => GetTargetsForLibrary(_lockFile, l));
}
public void PatchIfNecessary()
public void Patch()
{
var exportFilePath = GetExportFilePath(_lockFile.LockFilePath);
if (File.Exists(exportFilePath) && _msbuildTargetLibraries.Any())
{
var exportFile = LockFileReader.ReadExportFile(exportFilePath);

View file

@ -15,13 +15,13 @@ namespace Microsoft.DotNet.ProjectModel.Graph
{
public static class LockFileReader
{
public static LockFile Read(string lockFilePath, bool patchWithExportFile = true)
public static LockFile Read(string lockFilePath, bool designTime)
{
using (var stream = ResilientFileStreamOpener.OpenFile(lockFilePath))
{
try
{
return Read(lockFilePath, stream, patchWithExportFile);
return Read(lockFilePath, stream, designTime);
}
catch (FileFormatException ex)
{
@ -34,7 +34,7 @@ namespace Microsoft.DotNet.ProjectModel.Graph
}
}
public static LockFile Read(string lockFilePath, Stream stream, bool patchWithExportFile = true)
public static LockFile Read(string lockFilePath, Stream stream, bool designTime)
{
try
{
@ -48,15 +48,10 @@ namespace Microsoft.DotNet.ProjectModel.Graph
var lockFile = ReadLockFile(lockFilePath, jobject);
if (!designTime)
{
var patcher = new LockFilePatcher(lockFile);
if (patchWithExportFile)
{
patcher.PatchIfNecessary();
}
else
{
patcher.ThrowIfAnyMsbuildLibrariesPresent();
patcher.Patch();
}
return lockFile;

View file

@ -33,6 +33,8 @@ namespace Microsoft.DotNet.ProjectModel
private string ReferenceAssembliesPath { get; set; }
private bool IsDesignTime { get; set; }
private Func<string, Project> ProjectResolver { get; set; }
private Func<string, LockFile> LockFileResolver { get; set; }
@ -117,6 +119,12 @@ namespace Microsoft.DotNet.ProjectModel
return this;
}
public ProjectContextBuilder AsDesignTime()
{
IsDesignTime = true;
return this;
}
public IEnumerable<ProjectContext> BuildAllTargets()
{
ProjectDirectory = Project?.ProjectDirectory ?? ProjectDirectory;
@ -389,7 +397,12 @@ namespace Microsoft.DotNet.ProjectModel
}
}
private void ScanLibraries(LockFileTarget target, LockFileLookup lockFileLookup, Dictionary<LibraryKey, LibraryDescription> libraries, MSBuildDependencyProvider msbuildResolver, PackageDependencyProvider packageResolver, ProjectDependencyProvider projectResolver)
private void ScanLibraries(LockFileTarget target,
LockFileLookup lockFileLookup,
Dictionary<LibraryKey, LibraryDescription> libraries,
MSBuildDependencyProvider msbuildResolver,
PackageDependencyProvider packageResolver,
ProjectDependencyProvider projectResolver)
{
foreach (var library in target.Libraries)
{
@ -404,7 +417,7 @@ namespace Microsoft.DotNet.ProjectModel
{
if (MSBuildDependencyProvider.IsMSBuildProjectLibrary(projectLibrary))
{
description = msbuildResolver.GetDescription(TargetFramework, projectLibrary, library);
description = msbuildResolver.GetDescription(TargetFramework, projectLibrary, library, IsDesignTime);
type = LibraryType.MSBuildProject;
}
else
@ -483,7 +496,7 @@ namespace Microsoft.DotNet.ProjectModel
{
var projectLockJsonPath = Path.Combine(projectDir, LockFile.FileName);
return File.Exists(projectLockJsonPath) ?
LockFileReader.Read(Path.Combine(projectDir, LockFile.FileName)) :
LockFileReader.Read(Path.Combine(projectDir, LockFile.FileName), designTime: false) :
null;
}

View file

@ -21,11 +21,17 @@ namespace Microsoft.DotNet.ProjectModel.Resolution
_projectResolver = projectResolver;
}
public MSBuildProjectDescription GetDescription(NuGetFramework targetFramework, LockFileProjectLibrary projectLibrary, LockFileTargetLibrary targetLibrary)
public MSBuildProjectDescription GetDescription(NuGetFramework targetFramework,
LockFileProjectLibrary projectLibrary,
LockFileTargetLibrary targetLibrary,
bool isDesignTime)
{
// During design time fragment file could be missing. When fragment file is missing none of the
// assets can be found but it is acceptable during design time.
var compatible = targetLibrary.FrameworkAssemblies.Any() ||
targetLibrary.CompileTimeAssemblies.Any() ||
targetLibrary.RuntimeAssemblies.Any();
targetLibrary.RuntimeAssemblies.Any() ||
isDesignTime;
var dependencies = new List<LibraryRange>(targetLibrary.Dependencies.Count + targetLibrary.FrameworkAssemblies.Count);
PopulateDependencies(dependencies, targetLibrary, targetFramework);

View file

@ -211,7 +211,7 @@ namespace Microsoft.DotNet.ProjectModel
{
try
{
currentEntry.Model = LockFileReader.Read(currentEntry.FilePath, fs);
currentEntry.Model = LockFileReader.Read(currentEntry.FilePath, fs, designTime: true);
currentEntry.UpdateLastWriteTimeUtc();
}
catch (FileFormatException ex)
@ -257,7 +257,8 @@ namespace Microsoft.DotNet.ProjectModel
.WithProjectResolver(path => GetProject(path).Model)
.WithLockFileResolver(path => GetLockFile(path))
.WithProject(project)
.WithTargetFramework(framework.FrameworkName);
.WithTargetFramework(framework.FrameworkName)
.AsDesignTime();
currentEntry.ProjectContexts.Add(builder.Build());
}

View file

@ -21,7 +21,7 @@ namespace Microsoft.DotNet.ProjectModel.Tests
public void TestExportFileIsParsed()
{
var lockFilePath = GetLockFilePath("valid");
var lockFile = LockFileReader.Read(lockFilePath);
var lockFile = LockFileReader.Read(lockFilePath, designTime: false);
var exportFile = lockFile.ExportFile;
@ -41,7 +41,7 @@ namespace Microsoft.DotNet.ProjectModel.Tests
public void TestLockFileIsPatchedWithExportData()
{
var lockFilePath = GetLockFilePath("valid");
var lockFile = LockFileReader.Read(lockFilePath);
var lockFile = LockFileReader.Read(lockFilePath, designTime: false);
// check lock file structure is similar to export structure
foreach (var target in lockFile.Targets)
@ -59,7 +59,7 @@ namespace Microsoft.DotNet.ProjectModel.Tests
public void TestFragmentExistsButNoHolesInLockFile()
{
var lockFilePath = GetLockFilePath("valid_staleFragment");
var lockFile = LockFileReader.Read(lockFilePath);
var lockFile = LockFileReader.Read(lockFilePath, designTime: false);
var exportFile = lockFile.ExportFile;
@ -75,7 +75,16 @@ namespace Microsoft.DotNet.ProjectModel.Tests
{
var lockFilePath = GetLockFilePath("invalid_nofragment");
Assert.Throws<FileFormatException>(() => LockFileReader.Read(lockFilePath));
Assert.Throws<FileFormatException>(() => LockFileReader.Read(lockFilePath, designTime: false));
}
[Fact]
public void TestMissingExportUnderDesignTime()
{
var lockFilePath = GetLockFilePath("invalid_nofragment");
// not throw under design time scenario
Assert.NotNull(LockFileReader.Read(lockFilePath, designTime: true));
}
[Fact]
@ -83,7 +92,16 @@ namespace Microsoft.DotNet.ProjectModel.Tests
{
var lockFilePath = GetLockFilePath("invalid_missing-exports");
Assert.Throws<FileFormatException>(() => LockFileReader.Read(lockFilePath));
Assert.Throws<FileFormatException>(() => LockFileReader.Read(lockFilePath, designTime: false));
}
[Fact]
public void TestMissingExportsUnderDesignTime()
{
var lockFilePath = GetLockFilePath("invalid_missing-exports");
// not throw under design time scenario
Assert.NotNull(LockFileReader.Read(lockFilePath, designTime: true));
}
[Fact]
@ -91,7 +109,15 @@ namespace Microsoft.DotNet.ProjectModel.Tests
{
var lockFilePath = GetLockFilePath("invalid_missmatching-versions");
Assert.Throws<FileFormatException>(() => LockFileReader.Read(lockFilePath));
Assert.Throws<FileFormatException>(() => LockFileReader.Read(lockFilePath, designTime: false));
}
[Fact]
public void TestMissmatchingFileVersionsUnderDesignTime()
{
var lockFilePath = GetLockFilePath("invalid_missmatching-versions");
Assert.NotNull(LockFileReader.Read(lockFilePath, designTime: true));
}
private static int LibraryNumberFromName(Microsoft.DotNet.ProjectModel.Graph.LockFileTargetLibrary library)