Skip to content

Commit ebbe0d0

Browse files
committed
changes for CLI issues
1 parent 355bf5b commit ebbe0d0

File tree

5 files changed

+31
-6
lines changed

5 files changed

+31
-6
lines changed

src/Generator.Client.CommandLine/Program.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ static int Main(string[] args)
1717
{
1818
try
1919
{
20+
MSBuildInitializer.Initialize();
2021
ServiceLocatorInitializer.Initialize();
2122
#if DEBUG
2223
if (Debugger.IsAttached)

src/Generator.Client.Desktop/App.xaml.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public partial class App : Application
2020
protected override void OnStartup(StartupEventArgs e)
2121
{
2222
CommandManagerDelegate.Instance = new WpfCommandManager();
23+
MSBuildInitializer.Initialize();
2324
ServiceLocatorInitializer.Initialize();
2425
base.OnStartup(e);
2526
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2020 Andreas Müller
2+
// This file is a part of Amusoft.VisualStudio.TemplateGenerator and is licensed under Apache 2.0
3+
// See https://github.com/taori/Amusoft.VisualStudio.TemplateGenerator/blob/master/LICENSE for details
4+
5+
using System.Linq;
6+
using Microsoft.Build.Locator;
7+
using Microsoft.CodeAnalysis.MSBuild;
8+
9+
namespace Generator.Shared.DependencyInjection
10+
{
11+
public static class MSBuildInitializer
12+
{
13+
public static void Initialize()
14+
{
15+
var options = new VisualStudioInstanceQueryOptions(){ DiscoveryTypes = DiscoveryType.VisualStudioSetup};
16+
MSBuildLocator.RegisterInstance(MSBuildLocator.QueryVisualStudioInstances(options).FirstOrDefault());
17+
}
18+
}
19+
}

src/Generator.Shared/Generator.Shared.csproj

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>net472;netstandard2.0</TargetFrameworks>
4+
<!-- <TargetFrameworks>net472;netstandard2.0</TargetFrameworks> -->
5+
<TargetFrameworks>net472</TargetFrameworks>
56
<LangVersion>latest</LangVersion>
67
</PropertyGroup>
78

@@ -32,9 +33,10 @@
3233

3334
<ItemGroup>
3435
<PackageReference Include="JetBrains.Annotations" Version="2018.2.1" />
35-
<PackageReference Include="Microsoft.Build" Version="16.4.0" />
36-
<PackageReference Include="Microsoft.Build.Framework" Version="16.4.0" />
37-
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="16.4.0" />
36+
37+
<PackageReference Include="Microsoft.Build" Version="15.9.20" ExcludeAssets="runtime" />
38+
<PackageReference Include="Microsoft.Build.Framework" Version="15.9.20" ExcludeAssets="runtime" />
39+
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="15.9.20" ExcludeAssets="runtime" />
3840
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.Common" Version="3.4.0" />
3941
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.MSBuild" Version="3.4.0" />
4042
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.2.0" />
@@ -45,6 +47,8 @@
4547
<PackageReference Include="System.IO" Version="4.3.0" />
4648
<PackageReference Include="System.IO.Compression.ZipFile" Version="4.3.0" />
4749
<PackageReference Include="System.Reactive" Version="4.1.2" />
50+
<PackageReference Include="Microsoft.Build.Locator" Version="1.2.6" />
51+
4852
</ItemGroup>
4953

5054
</Project>

src/Generator.Shared/Transformation/SolutionExplorer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ public static string GetAssemblyName(string projectFile)
6161
throw new FileNotFoundException(projectFile);
6262

6363
var evaluationProject = GetEvaluationProject(projectFile);
64-
// var props = evaluationProject.Properties.Where(d => d.EvaluatedValue.Contains("ViewModels")).ToArray();
6564
return evaluationProject.GetPropertyValue("RootNamespace") ?? string.Empty;
6665
}
6766

@@ -150,7 +149,8 @@ private static Microsoft.Build.Evaluation.Project GetEvaluationProject(string pr
150149

151150
var matchingProject = Microsoft.Build.Evaluation.ProjectCollection.GlobalProjectCollection.LoadedProjects.FirstOrDefault(d => string.Equals(d.FullPath,projectFilePath, StringComparison.OrdinalIgnoreCase) );
152151

153-
return matchingProject ?? Microsoft.Build.Evaluation.Project.FromFile(projectFilePath, new ProjectOptions());
152+
var projectOptions = new ProjectOptions();
153+
return matchingProject ?? Microsoft.Build.Evaluation.Project.FromFile(projectFilePath, projectOptions);
154154
}
155155

156156
public IEnumerable<string> GetAllProjectFiles()

0 commit comments

Comments
 (0)