Skip to content

Commit 33153fb

Browse files
authored
Try to auto detect .NET Framework projects (#383)
1 parent 2a815a6 commit 33153fb

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

snippets5000/Snippets5000/Program.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,20 @@ private static async Task CompileProjects(string sourcePath, string[] projectsTo
224224
{
225225
Log.Write(2, $"Unable to load config file: {e1.StackTrace}");
226226
}
227-
227+
}
228+
229+
// Config not found, try and peek at the project to see if it's framework
230+
else if (!projectPath.EndsWith("sln", StringComparison.OrdinalIgnoreCase))
231+
{
232+
string firstLine = File.ReadLines(projectPath).First();
233+
234+
if (firstLine.StartsWith("<project", StringComparison.OrdinalIgnoreCase)
235+
&& firstLine.Contains("toolsversion", StringComparison.OrdinalIgnoreCase)
236+
&& !firstLine.Contains("sdk=", StringComparison.OrdinalIgnoreCase))
237+
{
238+
Log.Write(2, "Detected .NET Framework project file. Switching to Visual Studio as the host.");
239+
config.Host = "visualstudio";
240+
}
228241
}
229242

230243
Log.Write(2, $"Mode: {config.Host}");

snippets5000/Snippets5000/Snippets5000.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
88

9-
<Version>4.1.0.0</Version>
9+
<Version>4.2.0.0</Version>
1010
<AssemblyTitle>Snippets 5000</AssemblyTitle>
1111
<Authors>Andy De George</Authors>
1212
<Company>Microsoft</Company>

0 commit comments

Comments
 (0)