-
-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
d205d31
commit e2c70c1
Showing
12 changed files
with
172 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace Buildalyzer.Environment | ||
{ | ||
internal abstract class BuildEnvironment | ||
{ | ||
private string _oldMsBuildExtensionsPath = null; | ||
private string _oldMsBuildSdksPath = null; | ||
|
||
public abstract string GetToolsPath(); | ||
|
||
public virtual Dictionary<string, string> GetGlobalProperties(string solutionDir) => | ||
new Dictionary<string, string> | ||
{ | ||
{ MsBuildProperties.SolutionDir, solutionDir }, | ||
{ MsBuildProperties.DesignTimeBuild, "true" }, | ||
{ MsBuildProperties.BuildProjectReferences, "false" }, | ||
{ MsBuildProperties.SkipCompilerExecution, "true" }, | ||
{ MsBuildProperties.ProvideCommandLineArgs, "true" }, | ||
// Workaround for a problem with resource files, see https://github.com/dotnet/sdk/issues/346#issuecomment-257654120 | ||
{ MsBuildProperties.GenerateResourceMSBuildArchitecture, "CurrentArchitecture" } | ||
}; | ||
|
||
public virtual void SetEnvironmentVars(IReadOnlyDictionary<string, string> globalProperties) | ||
{ | ||
if (globalProperties.TryGetValue(MsBuildProperties.MSBuildExtensionsPath, out var msBuildExtensionsPath)) | ||
{ | ||
_oldMsBuildExtensionsPath = System.Environment.GetEnvironmentVariable(MsBuildProperties.MSBuildExtensionsPath); | ||
System.Environment.SetEnvironmentVariable(MsBuildProperties.MSBuildExtensionsPath, msBuildExtensionsPath); | ||
} | ||
if (globalProperties.TryGetValue(MsBuildProperties.MSBuildSDKsPath, out var msBuildSDKsPath)) | ||
{ | ||
_oldMsBuildSdksPath = System.Environment.GetEnvironmentVariable(MsBuildProperties.MSBuildSDKsPath); | ||
System.Environment.SetEnvironmentVariable(MsBuildProperties.MSBuildSDKsPath, msBuildSDKsPath); | ||
} | ||
} | ||
|
||
public virtual void UnsetEnvironmentVars() | ||
{ | ||
if (_oldMsBuildExtensionsPath != null) | ||
{ | ||
System.Environment.SetEnvironmentVariable(MsBuildProperties.MSBuildExtensionsPath, _oldMsBuildExtensionsPath); | ||
} | ||
if (_oldMsBuildSdksPath != null) | ||
{ | ||
System.Environment.SetEnvironmentVariable(MsBuildProperties.MSBuildSDKsPath, _oldMsBuildSdksPath); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using System.Collections.Generic; | ||
using System.Collections.Specialized; | ||
using System.IO; | ||
using System.Linq; | ||
|
||
namespace Buildalyzer.Environment | ||
{ | ||
|
||
// Based on code from OmniSharp | ||
// https://github.com/OmniSharp/omnisharp-roslyn/blob/78ccc8b4376c73da282a600ac6fb10fce8620b52/src/OmniSharp.Abstractions/Services/DotNetCliService.cs | ||
internal class CoreEnvironment : BuildEnvironment | ||
{ | ||
public string ToolsPath { get; } | ||
public string ExtensionsPath { get; } | ||
public string SDKsPath { get; } | ||
public string RoslynTargetsPath { get; } | ||
|
||
public CoreEnvironment(string projectPath) | ||
{ | ||
string dotnetPath = DotnetPathResolver.ResolvePath(projectPath); | ||
ToolsPath = dotnetPath; | ||
ExtensionsPath = dotnetPath; | ||
SDKsPath = Path.Combine(dotnetPath, "Sdks"); | ||
RoslynTargetsPath = Path.Combine(dotnetPath, "Roslyn"); | ||
} | ||
|
||
public override string GetToolsPath() => ToolsPath; | ||
|
||
public override Dictionary<string, string> GetGlobalProperties(string solutionDir) | ||
{ | ||
Dictionary<string, string> globalProperties = base.GetGlobalProperties(solutionDir); | ||
globalProperties.Add(MsBuildProperties.MSBuildExtensionsPath, ExtensionsPath); | ||
globalProperties.Add(MsBuildProperties.MSBuildSDKsPath, SDKsPath); | ||
globalProperties.Add(MsBuildProperties.RoslynTargetsPath, RoslynTargetsPath); | ||
return globalProperties; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/Buildalyzer/MsBuildProperties.cs → ...ldalyzer/Environment/MsBuildProperties.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
namespace Buildalyzer | ||
namespace Buildalyzer.Environment | ||
{ | ||
public static class MsBuildProperties | ||
{ | ||
|
This file was deleted.
Oops, something went wrong.
3 changes: 1 addition & 2 deletions
3
src/Buildalyzer/TextWriterLogger.cs → src/Buildalyzer/Logging/TextWriterLogger.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.