Skip to content

Commit

Permalink
Merge pull request #16924 from tamasvajk/feature/winforms-linux
Browse files Browse the repository at this point in the history
C#: Restore Windows dependencies when Windows Forms or WPF usage is detected
  • Loading branch information
tamasvajk authored Jul 11, 2024
2 parents 57efb84 + 7387c56 commit fd8cda3
Show file tree
Hide file tree
Showing 13 changed files with 188 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ private string GetRestoreArgs(RestoreSettings restoreSettings)
args += " --force";
}

if (restoreSettings.TargetWindows)
{
args += " /p:EnableWindowsTargeting=true";
}

return args;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public interface IDotNet
IList<string> GetNugetFeedsFromFolder(string folderPath);
}

public record class RestoreSettings(string File, string PackageDirectory, bool ForceDotnetRefAssemblyFetching, string? PathToNugetConfig = null, bool ForceReevaluation = false);
public record class RestoreSettings(string File, string PackageDirectory, bool ForceDotnetRefAssemblyFetching, string? PathToNugetConfig = null, bool ForceReevaluation = false, bool TargetWindows = false);

public partial record class RestoreResult(bool Success, IList<string> Output)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,13 @@ private IEnumerable<string> RestoreSolutions(out DependencyContainer dependencie
var successCount = 0;
var nugetSourceFailures = 0;
var assets = new Assets(logger);

var isWindows = fileContent.UseWindowsForms || fileContent.UseWpf;

var projects = fileProvider.Solutions.SelectMany(solution =>
{
logger.LogInfo($"Restoring solution {solution}...");
var res = dotnet.Restore(new(solution, PackageDirectory.DirInfo.FullName, ForceDotnetRefAssemblyFetching: true));
var res = dotnet.Restore(new(solution, PackageDirectory.DirInfo.FullName, ForceDotnetRefAssemblyFetching: true, TargetWindows: isWindows));
if (res.Success)
{
successCount++;
Expand Down Expand Up @@ -258,6 +261,9 @@ private void RestoreProjects(IEnumerable<string> projects, out ConcurrentBag<Dep
var successCount = 0;
var nugetSourceFailures = 0;
ConcurrentBag<DependencyContainer> collectedDependencies = [];

var isWindows = fileContent.UseWindowsForms || fileContent.UseWpf;

var sync = new object();
var projectGroups = projects.GroupBy(Path.GetDirectoryName);
Parallel.ForEach(projectGroups, new ParallelOptions { MaxDegreeOfParallelism = DependencyManager.Threads }, projectGroup =>
Expand All @@ -266,7 +272,7 @@ private void RestoreProjects(IEnumerable<string> projects, out ConcurrentBag<Dep
foreach (var project in projectGroup)
{
logger.LogInfo($"Restoring project {project}...");
var res = dotnet.Restore(new(project, PackageDirectory.DirInfo.FullName, ForceDotnetRefAssemblyFetching: true));
var res = dotnet.Restore(new(project, PackageDirectory.DirInfo.FullName, ForceDotnetRefAssemblyFetching: true, TargetWindows: isWindows));
assets.AddDependenciesRange(res.AssetsFilePaths);
lock (sync)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
| [...]/microsoft.windowsdesktop.app.ref/8.0.1/ref/net8.0/Accessibility.dll |
| [...]/microsoft.windowsdesktop.app.ref/8.0.1/ref/net8.0/Microsoft.VisualBasic.Forms.dll |
| [...]/microsoft.windowsdesktop.app.ref/8.0.1/ref/net8.0/Microsoft.VisualBasic.dll |
| [...]/microsoft.windowsdesktop.app.ref/8.0.1/ref/net8.0/Microsoft.Win32.Registry.AccessControl.dll |
| [...]/microsoft.windowsdesktop.app.ref/8.0.1/ref/net8.0/Microsoft.Win32.SystemEvents.dll |
| [...]/microsoft.windowsdesktop.app.ref/8.0.1/ref/net8.0/PresentationCore.dll |
| [...]/microsoft.windowsdesktop.app.ref/8.0.1/ref/net8.0/PresentationFramework.Aero2.dll |
| [...]/microsoft.windowsdesktop.app.ref/8.0.1/ref/net8.0/PresentationFramework.Aero.dll |
| [...]/microsoft.windowsdesktop.app.ref/8.0.1/ref/net8.0/PresentationFramework.AeroLite.dll |
| [...]/microsoft.windowsdesktop.app.ref/8.0.1/ref/net8.0/PresentationFramework.Classic.dll |
| [...]/microsoft.windowsdesktop.app.ref/8.0.1/ref/net8.0/PresentationFramework.Luna.dll |
| [...]/microsoft.windowsdesktop.app.ref/8.0.1/ref/net8.0/PresentationFramework.Royale.dll |
| [...]/microsoft.windowsdesktop.app.ref/8.0.1/ref/net8.0/PresentationFramework.dll |
| [...]/microsoft.windowsdesktop.app.ref/8.0.1/ref/net8.0/PresentationUI.dll |
| [...]/microsoft.windowsdesktop.app.ref/8.0.1/ref/net8.0/ReachFramework.dll |
| [...]/microsoft.windowsdesktop.app.ref/8.0.1/ref/net8.0/System.CodeDom.dll |
| [...]/microsoft.windowsdesktop.app.ref/8.0.1/ref/net8.0/System.Configuration.ConfigurationManager.dll |
| [...]/microsoft.windowsdesktop.app.ref/8.0.1/ref/net8.0/System.Design.dll |
| [...]/microsoft.windowsdesktop.app.ref/8.0.1/ref/net8.0/System.Diagnostics.EventLog.dll |
| [...]/microsoft.windowsdesktop.app.ref/8.0.1/ref/net8.0/System.Diagnostics.PerformanceCounter.dll |
| [...]/microsoft.windowsdesktop.app.ref/8.0.1/ref/net8.0/System.DirectoryServices.dll |
| [...]/microsoft.windowsdesktop.app.ref/8.0.1/ref/net8.0/System.Drawing.Common.dll |
| [...]/microsoft.windowsdesktop.app.ref/8.0.1/ref/net8.0/System.Drawing.Design.dll |
| [...]/microsoft.windowsdesktop.app.ref/8.0.1/ref/net8.0/System.Drawing.dll |
| [...]/microsoft.windowsdesktop.app.ref/8.0.1/ref/net8.0/System.IO.Packaging.dll |
| [...]/microsoft.windowsdesktop.app.ref/8.0.1/ref/net8.0/System.Printing.dll |
| [...]/microsoft.windowsdesktop.app.ref/8.0.1/ref/net8.0/System.Resources.Extensions.dll |
| [...]/microsoft.windowsdesktop.app.ref/8.0.1/ref/net8.0/System.Security.Cryptography.Pkcs.dll |
| [...]/microsoft.windowsdesktop.app.ref/8.0.1/ref/net8.0/System.Security.Cryptography.ProtectedData.dll |
| [...]/microsoft.windowsdesktop.app.ref/8.0.1/ref/net8.0/System.Security.Cryptography.Xml.dll |
| [...]/microsoft.windowsdesktop.app.ref/8.0.1/ref/net8.0/System.Security.Permissions.dll |
| [...]/microsoft.windowsdesktop.app.ref/8.0.1/ref/net8.0/System.Threading.AccessControl.dll |
| [...]/microsoft.windowsdesktop.app.ref/8.0.1/ref/net8.0/System.Windows.Controls.Ribbon.dll |
| [...]/microsoft.windowsdesktop.app.ref/8.0.1/ref/net8.0/System.Windows.Extensions.dll |
| [...]/microsoft.windowsdesktop.app.ref/8.0.1/ref/net8.0/System.Windows.Forms.Design.Editors.dll |
| [...]/microsoft.windowsdesktop.app.ref/8.0.1/ref/net8.0/System.Windows.Forms.Design.dll |
| [...]/microsoft.windowsdesktop.app.ref/8.0.1/ref/net8.0/System.Windows.Forms.Primitives.dll |
| [...]/microsoft.windowsdesktop.app.ref/8.0.1/ref/net8.0/System.Windows.Forms.dll |
| [...]/microsoft.windowsdesktop.app.ref/8.0.1/ref/net8.0/System.Windows.Input.Manipulations.dll |
| [...]/microsoft.windowsdesktop.app.ref/8.0.1/ref/net8.0/System.Windows.Presentation.dll |
| [...]/microsoft.windowsdesktop.app.ref/8.0.1/ref/net8.0/System.Xaml.dll |
| [...]/microsoft.windowsdesktop.app.ref/8.0.1/ref/net8.0/UIAutomationClient.dll |
| [...]/microsoft.windowsdesktop.app.ref/8.0.1/ref/net8.0/UIAutomationClientSideProviders.dll |
| [...]/microsoft.windowsdesktop.app.ref/8.0.1/ref/net8.0/UIAutomationProvider.dll |
| [...]/microsoft.windowsdesktop.app.ref/8.0.1/ref/net8.0/UIAutomationTypes.dll |
| [...]/microsoft.windowsdesktop.app.ref/8.0.1/ref/net8.0/WindowsBase.dll |
| [...]/microsoft.windowsdesktop.app.ref/8.0.1/ref/net8.0/WindowsFormsIntegration.dll |
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import csharp

private string getPath(Assembly a) {
not a.getCompilation().getOutputAssembly() = a and
exists(string s | s = a.getFile().getAbsolutePath() |
result = "[...]" + s.substring(s.indexOf("microsoft.windowsdesktop.app.ref") - 1, s.length())
)
}

from Assembly a
select getPath(a)
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
| All Nuget feeds reachable | 1.0 |
| Failed project restore with package source error | 0.0 |
| Failed solution restore with package source error | 0.0 |
| NuGet feed responsiveness checked | 1.0 |
| Project files on filesystem | 1.0 |
| Reachable fallback Nuget feed count | 1.0 |
| Resource extraction enabled | 0.0 |
| Restored .NET framework variants | 1.0 |
| Restored projects through solution files | 0.0 |
| Solution files on filesystem | 0.0 |
| Source files generated | 1.0 |
| Source files on filesystem | 3.0 |
| Successfully restored project files | 1.0 |
| Successfully restored solution files | 0.0 |
| Unresolved references | 0.0 |
| UseWPF set | 0.0 |
| UseWindowsForms set | 1.0 |
| WebView extraction enabled | 1.0 |
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import csharp
import semmle.code.csharp.commons.Diagnostics

query predicate compilationInfo(string key, float value) {
key != "Resolved references" and
key != "Resolved assembly conflicts" and
not key.matches("Compiler diagnostic count for%") and
exists(Compilation c, string infoKey, string infoValue | infoValue = c.getInfo(infoKey) |
key = infoKey and
value = infoValue.toFloat()
or
not exists(infoValue.toFloat()) and
key = infoKey + ": " + infoValue and
value = 1
)
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace winforms;

public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace winforms;

static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.Run(new Form1());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"sdk": {
"version": "8.0.101"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from create_database_utils import *

run_codeql_database_create(lang="csharp", extra_args=["--build-mode=none"])
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

</Project>

0 comments on commit fd8cda3

Please sign in to comment.