Skip to content
This repository has been archived by the owner on May 17, 2024. It is now read-only.

Commit

Permalink
check user TFM input
Browse files Browse the repository at this point in the history
  • Loading branch information
jmarolf committed Mar 24, 2020
1 parent fbf3580 commit ba22657
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/MSBuild.Conversion.SDK/TargetFrameworkHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.IO.Compression;
using System.Linq;
using System.Text.Json;
using System.Text.RegularExpressions;

using Microsoft.Build.Locator;

Expand All @@ -12,6 +13,9 @@ namespace MSBuild.Conversion.SDK
{
public static class TargetFrameworkHelper
{
/// <summary>
/// Determine the TFM to use based on what is installed on the users machine
/// </summary>
public static string FindHighestInstalledTargetFramework(bool usePreviewSDK)
{
// Finds SDK path
Expand Down Expand Up @@ -72,5 +76,11 @@ public static string FindHighestInstalledTargetFramework(bool usePreviewSDK)
}

}

/// <summary>
/// Regect obviously wrong TFM specifiers
/// </summary>
public static bool IsValidTargetFramework(string tfm)
=> !tfm.Contains("-") && !tfm.Contains(" ") && tfm.Contains("net") && Regex.Match(tfm, "[0-9]").Success;
}
}
9 changes: 9 additions & 0 deletions src/try-convert/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ public static int Run(string project, string workspace, string msbuildPath, stri
{
tfm = TargetFrameworkHelper.FindHighestInstalledTargetFramework(allowPreviews);
}
else
{
tfm = tfm.Trim();
if(!TargetFrameworkHelper.IsValidTargetFramework(tfm))
{
Console.WriteLine($"Invalid framework specified for --target-framework: '{tfm}'");
return -1;
}
}

var currentDirectory = Environment.CurrentDirectory;
var workspacePath = string.Empty;
Expand Down

0 comments on commit ba22657

Please sign in to comment.