This commit is contained in:
Livar Cunha 2016-10-03 18:41:10 -07:00
parent e5f6107d88
commit 12e8e8eca7
2 changed files with 52 additions and 1 deletions

View file

@ -0,0 +1,52 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.IO;
using Microsoft.Build.Execution;
using NuGet.ProjectModel;
namespace Microsoft.DotNet.Cli.Utils
{
internal class LockFilePathCalculator
{
public string GetLockFilePath(string projectDirectory)
{
return ResolveLockFilePathUsingCSProj(projectDirectory) ??
ReturnProjectLockJson(projectDirectory);
}
private string ResolveLockFilePathUsingCSProj(string projectDirectory)
{
string csProjPath = GetCSProjPath(projectDirectory);
if(csProjPath != null)
{
ProjectInstance projectInstance = new ProjectInstance(csProjPath, null, null);
}
return null;
}
private string ReturnProjectLockJson(string projectDirectory)
{
return Path.Combine(projectDirectory, LockFileFormat.LockFileName);
}
private string GetCSProjPath(string projectDirectory)
{
string[] projectFiles = Directory.GetFiles(projectDirectory, "*.*proj");
if (projectFiles.Length == 0)
{
return null;
}
else if (projectFiles.Length > 1)
{
throw new InvalidOperationException(
$"Specify which project file to use because this '{projectDirectory}' contains more than one project file.");
}
return projectFiles[0];
}
}
}

View file

@ -7,7 +7,6 @@ using Microsoft.DotNet.ProjectModel;
using Microsoft.DotNet.Tools.Common;
using Microsoft.Extensions.DependencyModel;
using NuGet.Frameworks;
using NuGet.LibraryModel;
using NuGet.ProjectModel;
using NuGet.Versioning;
using FileFormatException = Microsoft.DotNet.ProjectModel.FileFormatException;