Remove fragment file's involvement in design time scenarios
This commit is contained in:
parent
429eb93cd9
commit
e176c1d3b9
7 changed files with 44 additions and 30 deletions
|
@ -141,7 +141,7 @@ namespace Microsoft.DotNet.Cli.Utils
|
|||
|
||||
try
|
||||
{
|
||||
lockFile = LockFileReader.Read(lockFilePath);
|
||||
lockFile = LockFileReader.Read(lockFilePath, designTime: false);
|
||||
}
|
||||
catch (FileFormatException ex)
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
|
|
@ -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,7 @@ 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]
|
||||
|
@ -83,7 +83,7 @@ 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]
|
||||
|
@ -91,7 +91,7 @@ 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));
|
||||
}
|
||||
|
||||
private static int LibraryNumberFromName(Microsoft.DotNet.ProjectModel.Graph.LockFileTargetLibrary library)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue