Skip to content

Commit

Permalink
Use MSBuildProjectExtensionsPath instead of BaseIntermediateOutputPat…
Browse files Browse the repository at this point in the history
…h in VS project adapters
  • Loading branch information
dsplaisted committed Mar 7, 2018
1 parent cb7ce66 commit 09f1311
Show file tree
Hide file tree
Showing 13 changed files with 68 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public override async Task<string> GetAssetsFilePathAsync()
public override async Task<string> GetCacheFilePathAsync()
{
await _threadingService.JoinableTaskFactory.SwitchToMainThreadAsync();
return NoOpRestoreUtilities.GetProjectCacheFilePath(cacheRoot: GetBaseIntermediatePath(), projectPath: _projectFullPath);
return NoOpRestoreUtilities.GetProjectCacheFilePath(cacheRoot: GetMSBuildProjectExtensionsPath(), projectPath: _projectFullPath);
}

public override async Task<string> GetAssetsFilePathOrNullAsync()
Expand All @@ -91,7 +91,7 @@ private async Task<string> GetAssetsFilePathAsync(bool shouldThrow)
{
await _threadingService.JoinableTaskFactory.SwitchToMainThreadAsync();

var baseIntermediatePath = GetBaseIntermediatePath(shouldThrow);
var baseIntermediatePath = GetMSBuildProjectExtensionsPath(shouldThrow);

if (baseIntermediatePath == null)
{
Expand Down Expand Up @@ -164,25 +164,25 @@ public override async Task<bool> UninstallPackageAsync(

#endregion

private string GetBaseIntermediatePath(bool shouldThrow = true)
private string GetMSBuildProjectExtensionsPath(bool shouldThrow = true)
{
ThreadHelper.ThrowIfNotOnUIThread();

var baseIntermediatePath = _vsProjectAdapter.BaseIntermediateOutputPath;
var msbuildProjectExtensionsPath = _vsProjectAdapter.MSBuildProjectExtensionsPath;

if (string.IsNullOrEmpty(baseIntermediatePath))
if (string.IsNullOrEmpty(msbuildProjectExtensionsPath))
{
if (shouldThrow)
{
throw new InvalidDataException(string.Format(
Strings.BaseIntermediateOutputPathNotFound,
Strings.MSBuildProjectExtensionsPathNotFound,
_vsProjectAdapter.ProjectDirectory));
}

return null;
}

return baseIntermediatePath;
return msbuildProjectExtensionsPath;
}

private string GetPackagesPath(ISettings settings)
Expand Down Expand Up @@ -337,7 +337,7 @@ private async Task<PackageSpec> GetPackageSpecAsync(ISettings settings)
RestoreMetadata = new ProjectRestoreMetadata
{
ProjectStyle = ProjectStyle.PackageReference,
OutputPath = GetBaseIntermediatePath(),
OutputPath = GetMSBuildProjectExtensionsPath(),
ProjectPath = _projectFullPath,
ProjectName = projectName,
ProjectUniqueName = _projectFullPath,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,18 @@ internal class VsProjectAdapter : IVsProjectAdapter

#region Properties

public string BaseIntermediateOutputPath
public string MSBuildProjectExtensionsPath
{
get
{
var baseIntermediateOutputPath = BuildProperties.GetPropertyValue(ProjectBuildProperties.BaseIntermediateOutputPath);
var msbuildProjectExtensionsPath = BuildProperties.GetPropertyValue(ProjectBuildProperties.MSBuildProjectExtensionsPath);

if (string.IsNullOrEmpty(baseIntermediateOutputPath))
if (string.IsNullOrEmpty(msbuildProjectExtensionsPath))
{
return null;
}

return Path.Combine(ProjectDirectory, baseIntermediateOutputPath);
return Path.Combine(ProjectDirectory, msbuildProjectExtensionsPath);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,23 @@ public VsProjectJsonNuGetProject(
ProjectServices = projectServices;
}

protected override async Task<string> GetBaseIntermediatePathAsync()
protected override async Task<string> GetMSBuildProjectExtensionsPathAsync()
{
var baseIntermediatePath = await ProjectServices.BuildProperties.GetPropertyValueAsync(ProjectBuildProperties.BaseIntermediateOutputPath);
var msbuildProjectExtensionsPath = await ProjectServices.BuildProperties.GetPropertyValueAsync(ProjectBuildProperties.MSBuildProjectExtensionsPath);

if (string.IsNullOrEmpty(baseIntermediatePath))
if (string.IsNullOrEmpty(msbuildProjectExtensionsPath))
{
throw new InvalidDataException(string.Format(
Strings.BaseIntermediateOutputPathNotFound,
Strings.MSBuildProjectExtensionsPathNotFound,
MSBuildProjectPath));
}

return UriUtility.GetAbsolutePathFromFile(MSBuildProjectPath, baseIntermediatePath);
return UriUtility.GetAbsolutePathFromFile(MSBuildProjectPath, msbuildProjectExtensionsPath);
}

public override async Task<string> GetCacheFilePathAsync()
{
return NoOpRestoreUtilities.GetProjectCacheFilePath(await GetBaseIntermediatePathAsync(), MSBuildProjectPath);
return NoOpRestoreUtilities.GetProjectCacheFilePath(await GetMSBuildProjectExtensionsPathAsync(), MSBuildProjectPath);
}

protected override async Task UpdateInternalTargetFrameworkAsync()
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@
<data name="ProjectNotLoaded_RestoreFailed" xml:space="preserve">
<value>The operation failed as details for project {0} could not be loaded.</value>
</data>
<data name="BaseIntermediateOutputPathNotFound" xml:space="preserve">
<value>The BaseIntermediateOutputPath MSBuild property could not be found for project '{0}'.</value>
<data name="MSBuildProjectExtensionsPathNotFound" xml:space="preserve">
<value>The MSBuildProjectExtensionsPath MSBuild property could not be found for project '{0}'.</value>
<comment>{0} is the full path to the project.</comment>
</data>
<data name="ProjectCouldNotBeCastedToBuildPropertyStorage" xml:space="preserve">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ public interface IVsProjectAdapter
string AssetTargetFallback { get; }

/// <summary>
/// BaseIntermediateOutputPath project property (e.g. c:\projFoo\obj)
/// MSBuildProjectExtensionsPath project property (e.g. c:\projFoo\obj)
/// </summary>
string BaseIntermediateOutputPath { get; }
string MSBuildProjectExtensionsPath { get; }

IProjectBuildProperties BuildProperties { get; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ private RestoreSummaryRequest Create(
ProjectStyle = project.PackageSpec.RestoreMetadata.ProjectStyle,
RestoreOutputPath = project.PackageSpec.RestoreMetadata.ProjectStyle == ProjectStyle.ProjectJson ? rootPath : project.PackageSpec.RestoreMetadata.OutputPath,
DependencyGraphSpec = projectDgSpec,
BaseIntermediateOutputPath = projectPackageSpec.RestoreMetadata.OutputPath,
ParentId = restoreArgs.ParentId
};

Expand Down
10 changes: 2 additions & 8 deletions src/NuGet.Core/NuGet.Commands/RestoreCommand/RestoreRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,10 @@ public RestoreRequest(
public ProjectStyle ProjectStyle { get; set; } = ProjectStyle.Unknown;

/// <summary>
/// Restore output path
/// MSBuildProjectExtensionsPath, which is where the restore output will go
/// </summary>
public string RestoreOutputPath { get; set; }
public string MSBuildProjectExtensionsPath { get; set; }

/// <summary>
/// Base Intermediate output path
/// </summary>
public string BaseIntermediateOutputPath { get; set; }


/// <summary>
/// Compatibility options
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ internal static bool IsNoOpSupported(RestoreRequest request)
}

/// <summary>
/// The cache file path is $(BaseIntermediateOutputPath)\$(project).nuget.cache
/// The cache file path is $(MSBuildProjectExtensionsPath)\$(project).nuget.cache
/// </summary>
private static string GetBuildIntegratedProjectCacheFilePath(RestoreRequest request)
{
Expand All @@ -35,7 +35,7 @@ private static string GetBuildIntegratedProjectCacheFilePath(RestoreRequest requ
|| request.ProjectStyle == ProjectStyle.PackageReference
|| request.ProjectStyle == ProjectStyle.Standalone)
{
var cacheRoot = request.BaseIntermediateOutputPath ?? request.RestoreOutputPath;
var cacheRoot = request.MSBuildProjectExtensionsPath;
return request.Project.RestoreMetadata.CacheFilePath = GetProjectCacheFilePath(cacheRoot, request.Project.RestoreMetadata.ProjectPath);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace NuGet.ProjectManagement
/// </summary>
public static class ProjectBuildProperties
{
public const string BaseIntermediateOutputPath = "BaseIntermediateOutputPath";
public const string MSBuildProjectExtensionsPath = "MSBuildProjectExtensionsPath";
public const string PackageTargetFallback = "PackageTargetFallback";
public const string AssetTargetFallback = "AssetTargetFallback";
public const string PackageVersion = "PackageVersion";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,10 @@ public override async Task<IEnumerable<PackageReference>> GetInstalledPackagesAs
return packages;
}

protected virtual Task<string> GetBaseIntermediatePathAsync()
protected virtual Task<string> GetMSBuildProjectExtensionsPathAsync()
{
// Extending class will implement the functionality.
return Task.FromResult((string) null);
// Extending class will implement the functionality (but this method can't be abstract as tests create it directly)
return Task.FromResult((string)null);
}

public override async Task<IReadOnlyList<PackageSpec>> GetPackageSpecsAsync(DependencyGraphCacheContext context)
Expand All @@ -172,7 +172,7 @@ public override async Task<IReadOnlyList<PackageSpec>> GetPackageSpecsAsync(Depe
packageSpec.RestoreMetadata = metadata;

metadata.ProjectStyle = ProjectStyle.ProjectJson;
metadata.OutputPath = await GetBaseIntermediatePathAsync();
metadata.OutputPath = await GetMSBuildProjectExtensionsPathAsync();
metadata.ProjectPath = MSBuildProjectPath;
metadata.ProjectJsonPath = packageSpec.FilePath;
metadata.ProjectName = packageSpec.Name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,17 @@ public LegacyPackageReferenceProjectTests(DispatcherThreadFixture fixture)
}

[Fact]
public async Task GetAssetsFilePathAsync_WithValidBaseIntermediateOutputPath_Succeeds()
public async Task GetAssetsFilePathAsync_WithValidMSBuildProjectExtensionsPath_Succeeds()
{
// Arrange
using (var testDirectory = TestDirectory.Create())
{
var testBaseIntermediateOutputPath = Path.Combine(testDirectory, "obj");
Directory.CreateDirectory(testBaseIntermediateOutputPath);
var testMSBuildProjectExtensionsPath = Path.Combine(testDirectory, "obj");
Directory.CreateDirectory(testMSBuildProjectExtensionsPath);
var projectAdapter = Mock.Of<IVsProjectAdapter>();
Mock.Get(projectAdapter)
.SetupGet(x => x.BaseIntermediateOutputPath)
.Returns(testBaseIntermediateOutputPath);
.SetupGet(x => x.MSBuildProjectExtensionsPath)
.Returns(testMSBuildProjectExtensionsPath);

var testProject = new LegacyPackageReferenceProject(
projectAdapter,
Expand All @@ -67,16 +67,16 @@ public async Task GetAssetsFilePathAsync_WithValidBaseIntermediateOutputPath_Suc
var assetsPath = await testProject.GetAssetsFilePathAsync();

// Assert
Assert.Equal(Path.Combine(testBaseIntermediateOutputPath, "project.assets.json"), assetsPath);
Assert.Equal(Path.Combine(testMSBuildProjectExtensionsPath, "project.assets.json"), assetsPath);

// Verify
Mock.Get(projectAdapter)
.VerifyGet(x => x.BaseIntermediateOutputPath, Times.AtLeastOnce);
.VerifyGet(x => x.MSBuildProjectExtensionsPath, Times.AtLeastOnce);
}
}

[Fact]
public async Task GetAssetsFilePathAsync_WithNoBaseIntermediateOutputPath_Throws()
public async Task GetAssetsFilePathAsync_WithNoMSBuildProjectExtensionsPath_Throws()
{
// Arrange
using (TestDirectory.Create())
Expand All @@ -96,18 +96,18 @@ await Assert.ThrowsAsync<InvalidDataException>(
}

[Fact]
public async Task GetCacheFilePathAsync_WithValidBaseIntermediateOutputPath_Succeeds()
public async Task GetCacheFilePathAsync_WithValidMSBuildProjectExtensionsPath_Succeeds()
{
// Arrange
using (var testDirectory = TestDirectory.Create())
{
var testProj = "project.csproj";
var testBaseIntermediateOutputPath = Path.Combine(testDirectory, "obj");
Directory.CreateDirectory(testBaseIntermediateOutputPath);
var testMSBuildProjectExtensionsPath = Path.Combine(testDirectory, "obj");
Directory.CreateDirectory(testMSBuildProjectExtensionsPath);
var projectAdapter = Mock.Of<IVsProjectAdapter>();
Mock.Get(projectAdapter)
.SetupGet(x => x.BaseIntermediateOutputPath)
.Returns(testBaseIntermediateOutputPath);
.SetupGet(x => x.MSBuildProjectExtensionsPath)
.Returns(testMSBuildProjectExtensionsPath);

Mock.Get(projectAdapter)
.SetupGet(x => x.FullProjectPath)
Expand All @@ -125,16 +125,16 @@ public async Task GetCacheFilePathAsync_WithValidBaseIntermediateOutputPath_Succ
var cachePath = await testProject.GetCacheFilePathAsync();

// Assert
Assert.Equal(Path.Combine(testBaseIntermediateOutputPath, $"{testProj}.nuget.cache"), cachePath);
Assert.Equal(Path.Combine(testMSBuildProjectExtensionsPath, $"{testProj}.nuget.cache"), cachePath);

// Verify
Mock.Get(projectAdapter)
.VerifyGet(x => x.BaseIntermediateOutputPath, Times.AtLeastOnce);
.VerifyGet(x => x.MSBuildProjectExtensionsPath, Times.AtLeastOnce);
}
}

[Fact]
public async Task GetCacheFilePathAsync_WithNoBaseIntermediateOutputPath_Throws()
public async Task GetCacheFilePathAsync_WithNoMSBuildProjectExtensionsPath_Throws()
{
// Arrange
using (TestDirectory.Create())
Expand All @@ -160,12 +160,12 @@ public async Task GetCacheFilePathAsync_SwitchesToMainThread_Succeeds()
using (var testDirectory = TestDirectory.Create())
{
var testProj = "project.csproj";
var testBaseIntermediateOutputPath = Path.Combine(testDirectory, "obj");
Directory.CreateDirectory(testBaseIntermediateOutputPath);
var testMSBuildProjectExtensionsPath = Path.Combine(testDirectory, "obj");
Directory.CreateDirectory(testMSBuildProjectExtensionsPath);
var projectAdapter = Mock.Of<IVsProjectAdapter>();
Mock.Get(projectAdapter)
.SetupGet(x => x.BaseIntermediateOutputPath)
.Returns(testBaseIntermediateOutputPath);
.SetupGet(x => x.MSBuildProjectExtensionsPath)
.Returns(testMSBuildProjectExtensionsPath);

Mock.Get(projectAdapter)
.SetupGet(x => x.FullProjectPath)
Expand All @@ -181,11 +181,11 @@ public async Task GetCacheFilePathAsync_SwitchesToMainThread_Succeeds()
var assetsPath = await testProject.GetCacheFilePathAsync();

// Assert
Assert.Equal(Path.Combine(testBaseIntermediateOutputPath, $"{testProj}.nuget.cache"), assetsPath);
Assert.Equal(Path.Combine(testMSBuildProjectExtensionsPath, $"{testProj}.nuget.cache"), assetsPath);

// Verify
Mock.Get(projectAdapter)
.VerifyGet(x => x.BaseIntermediateOutputPath, Times.AtLeastOnce);
.VerifyGet(x => x.MSBuildProjectExtensionsPath, Times.AtLeastOnce);
}
}

Expand Down Expand Up @@ -776,11 +776,11 @@ private static IVsProjectAdapter CreateProjectAdapter(string fullPath)
.Setup(x => x.GetTargetFrameworkAsync())
.ReturnsAsync(NuGetFramework.Parse("netstandard13"));

var testBaseIntermediateOutputPath = Path.Combine(fullPath, "obj");
Directory.CreateDirectory(testBaseIntermediateOutputPath);
var testMSBuildProjectExtensionsPath = Path.Combine(fullPath, "obj");
Directory.CreateDirectory(testMSBuildProjectExtensionsPath);
projectAdapter
.Setup(x => x.BaseIntermediateOutputPath)
.Returns(testBaseIntermediateOutputPath);
.Setup(x => x.MSBuildProjectExtensionsPath)
.Returns(testMSBuildProjectExtensionsPath);

return projectAdapter.Object;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public SimpleTestProjectContext(string projectName, ProjectStyle type, string so
public string ProjectPath { get; set; }

/// <summary>
/// Base intermediate directory path
/// MSBuildProjectExtensionsPath
/// </summary>
public string OutputPath { get; set; }

Expand Down Expand Up @@ -396,7 +396,7 @@ public XDocument GetXML()
ProjectFileUtils.AddProperties(xml, new Dictionary<string, string>()
{
{ "ProjectGuid", "{" + ProjectGuid.ToString() + "}" },
{ "BaseIntermediateOutputPath", OutputPath },
{ "MSBuildProjectExtensionsPath", OutputPath },
{ "AssemblyName", ProjectName }
});

Expand Down

0 comments on commit 09f1311

Please sign in to comment.