Skip to content

Commit

Permalink
Use msbuild to get the obj folder path (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
nkolev92 authored Sep 21, 2022
1 parent 34b76c7 commit 5464466
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -348,3 +348,6 @@ MigrationBackup/

# Ionide (cross platform F# VS Code tools) working folder
.ionide/

# We don't need the runsettings
launchSettings.json
3 changes: 3 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageVersion Include="xunit" Version="2.4.1" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.4.3" />
<PackageVersion Include="Microsoft.Build" Version="17.3.1" />
<PackageVersion Include="Microsoft.Build.Locator" Version="1.5.5" />
<PackageVersion Include="Microsoft.Build.Framework" Version="17.3.1" />
</ItemGroup>


Expand Down
3 changes: 1 addition & 2 deletions src/Common/PackageDependencyNode.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using NuGet.Packaging.Core;
using NuGet.Versioning;
using NuGet.Versioning;
using System.Diagnostics;

namespace Common
Expand Down
5 changes: 4 additions & 1 deletion src/DependencyVisualizerTool/DependencyVisualizerTool.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
Expand All @@ -15,6 +15,9 @@

<ItemGroup>
<PackageReference Include="System.CommandLine" />
<PackageReference Include="Microsoft.Build" ExcludeAssets="runtime" />
<PackageReference Include="Microsoft.Build.Framework" ExcludeAssets="runtime" />
<PackageReference Include="Microsoft.Build.Locator" />
</ItemGroup>

<ItemGroup>
Expand Down
32 changes: 32 additions & 0 deletions src/DependencyVisualizerTool/MSBuildUtility.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Microsoft.Build.Construction;
using Microsoft.Build.Evaluation;
using Microsoft.Build.Exceptions;
using System.Globalization;

namespace DependencyVisualizerTool
{
internal class MSBuildUtility
{
private const string MSBuildProjectExtensionsPath = nameof(MSBuildProjectExtensionsPath);

public static string GetMSBuildProjectExtensionsPath(string projectFilePath)
{
var project = GetProject(projectFilePath);
return project.GetPropertyValue(MSBuildProjectExtensionsPath);
}

private static Project GetProject(string projectCSProjPath, IDictionary<string, string>? globalProperties = null)
{
try
{
var projectRootElement = ProjectRootElement.Open(projectCSProjPath, ProjectCollection.GlobalProjectCollection, preserveFormatting: true);
return new Project(projectRootElement);
}
catch (InvalidProjectFileException e)
{
throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, "Unable to open the project {0}", projectCSProjPath), e);
}
}

}
}
3 changes: 3 additions & 0 deletions src/DependencyVisualizerTool/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// See https://aka.ms/new-console-template for more information
using Microsoft.Build.Locator;
using System.CommandLine;

MSBuildLocator.RegisterDefaults();

var fileArgument = new Argument<FileInfo?>(
name: "assetsFile",
description: "The file to read and display on the console.",
Expand Down

0 comments on commit 5464466

Please sign in to comment.