Skip to content

Commit

Permalink
build: Remove Nuget.Restore.targets
Browse files Browse the repository at this point in the history
This was kzu's project[1] which had a very interesting goal: make
nuget restore be part of the build process itself (kind of like a
PreBuild target so that your IDE did the restore before building,
regardless if the IDE had nuget support or not).

Now, there's several reasons to remove it (ordered by level of
importance):

1. We're moving soon to dotnet v6 and newer, where a restore is always
assumed by the IDEs and command-line builds (the command is even called
"dotnet restore" itself, no need to specify "nuget" anymore, as the term
'restore' has become part of the dotnet jargon already).

2. Looking back, I introduced it in 2017 [2] but I kinda regret doing it
because of all the hacks (such as needing to generate the special file
'before.$solutionFileName.targets before the build) required to make it
work, the ugliness of its code (not really blaming the author here, maybe
MSBuild's XML syntax is generally unreadable), and:

3. The fact that despite the use of it, there were certain sccenarios that
needed an explicit restore of other solutions/projects to make the build
work with Xamarin.Forms.

So as there were explicit restores happening in make.fsx anyway, let's
make nuget restore explicitly handled now in all cases by make.fsx (this
quirk will not live very long anyway, just as long as the Xamarin.Forms
frontend lives, which is getting replaced by MAUI soon).

[1] https://github.com/kzu/Nuget.Restore
[2] 9804b65
  • Loading branch information
knocte committed Aug 13, 2023
1 parent 2dec7cb commit 4753743
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 209 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ TestResult.xml
# backup files of some editors such as nano
*~

# autogenerated file by configure.sh
before.gwallet.core-legacy.sln.targets

# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

Expand Down
170 changes: 0 additions & 170 deletions NuGet.Restore.targets

This file was deleted.

13 changes: 1 addition & 12 deletions scripts/configure.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ let initialConfigFile, buildTool, areGtkLibsAbsentOrDoesNotApply =
Process.ConfigCommandCheck ["mono"] true true |> ignore
Process.ConfigCommandCheck ["fsharpc"] true true |> ignore

// needed by NuGet.Restore.targets & the "update-servers" Makefile target
// needed by the "update-servers" Makefile target?
Process.ConfigCommandCheck ["curl"] true true
|> ignore

Expand Down Expand Up @@ -118,17 +118,6 @@ let initialConfigFile, buildTool, areGtkLibsAbsentOrDoesNotApply =

Map.empty.Add("MonoPkgConfigVersion", monoVersion), buildTool, areGtkLibsAbsentOrDoesNotApply

#if LEGACY_FRAMEWORK
let targetsFileToExecuteNugetBeforeBuild = """<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), NuGet.Restore.targets))\NuGet.Restore.targets"
Condition=" '$(NuGetRestoreImported)' != 'true' " />
</Project>
"""
File.WriteAllText(Path.Combine(rootDir.FullName, "before.gwallet.core-legacy.sln.targets"),
targetsFileToExecuteNugetBeforeBuild)
#endif

let prefix = DirectoryInfo(Misc.GatherOrGetDefaultPrefix(Misc.FsxOnlyArguments(), false, None))

if not (prefix.Exists) then
Expand Down
61 changes: 37 additions & 24 deletions scripts/make.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ open GWallet.Scripting
let UNIX_NAME = "geewallet"
let CONSOLE_FRONTEND = "GWallet.Frontend.Console"
let GTK_FRONTEND = "GWallet.Frontend.XF.Gtk"
let DEFAULT_SOLUTION_FILE = "gwallet.core.sln"
let DEFAULT_SOLUTION_FILE =
#if !LEGACY_FRAMEWORK
"gwallet.core.sln"
#else
"gwallet.core-legacy.sln"
#endif
let LINUX_SOLUTION_FILE = "gwallet.linux-legacy.sln"
let MAC_SOLUTION_FILE = "gwallet.mac-legacy.sln"
let BACKEND = "GWallet.Backend"
Expand Down Expand Up @@ -126,6 +131,18 @@ exec mono "$FRONTEND_PATH" "$@"
"""

#if LEGACY_FRAMEWORK
let NugetRestore projectOrSolutionRelativePath =
let nugetArgs =
sprintf
"restore %s -SolutionDirectory ."
projectOrSolutionRelativePath
Network.RunNugetCommand
FsxHelper.NugetExe
nugetArgs
Echo.All
true
|> ignore

let PrintNugetVersion () =
if not (FsxHelper.NugetExe.Exists) then
false
Expand Down Expand Up @@ -157,6 +174,10 @@ let BuildSolution
(maybeConstant: Option<string>)
(extraOptions: string)
=
#if LEGACY_FRAMEWORK
NugetRestore solutionFileName
#endif

let buildTool,buildArg = buildToolAndBuildArg

let configOption =
Expand Down Expand Up @@ -223,16 +244,16 @@ let BuildSolution

let JustBuild binaryConfig maybeConstant: Frontend*FileInfo =
let maybeBuildTool = Map.tryFind "BuildTool" buildConfigContents
let mainSolution = DEFAULT_SOLUTION_FILE
let buildTool,buildArg,solutionFileName =
let solutionFileName = DEFAULT_SOLUTION_FILE
let buildTool,buildArg =
match maybeBuildTool with
| None ->
failwith "A BuildTool should have been chosen by the configure script, please report this bug"
| Some "dotnet" ->
#if LEGACY_FRAMEWORK
failwith "'dotnet' shouldn't be the build tool when using legacy framework, please report this bug"
#endif
"dotnet", "build", mainSolution
"dotnet", "build"
| Some otherBuildTool ->
#if LEGACY_FRAMEWORK
let nugetConfig =
Expand All @@ -247,9 +268,9 @@ let JustBuild binaryConfig maybeConstant: Frontend*FileInfo =
|> FileInfo

File.Copy(legacyNugetConfig.FullName, nugetConfig.FullName, true)
otherBuildTool, String.Empty, "gwallet.core-legacy.sln"
otherBuildTool, String.Empty
#else
otherBuildTool, String.Empty, mainSolution
otherBuildTool, String.Empty
#endif

Console.WriteLine (sprintf "Building in %s mode..." (binaryConfig.ToString()))
Expand All @@ -265,22 +286,6 @@ let JustBuild binaryConfig maybeConstant: Frontend*FileInfo =
// older mono versions (which only have xbuild, not msbuild) can't compile .NET Standard assemblies
if buildTool = "msbuild" then

#if LEGACY_FRAMEWORK
// somehow, msbuild doesn't restore the frontend dependencies (e.g. Xamarin.Forms) when targetting
// the {LINUX|MAC}_SOLUTION_FILE below, so we need this workaround. TODO: report this bug
let ExplicitRestore projectOrSolutionRelativePath =
let nugetWorkaroundArgs =
sprintf
"restore %s -SolutionDirectory ."
projectOrSolutionRelativePath
Network.RunNugetCommand
FsxHelper.NugetExe
nugetWorkaroundArgs
Echo.All
true
|> ignore
#endif

let MSBuildRestoreAndBuild solutionFile =
BuildSolution ("msbuild",buildArg) solutionFile binaryConfig maybeConstant "/t:Restore"
// TODO: report as a bug the fact that /t:Restore;Build doesn't work while /t:Restore and later /t:Build does
Expand All @@ -293,7 +298,9 @@ let JustBuild binaryConfig maybeConstant: Frontend*FileInfo =
if binaryConfig = BinaryConfig.Debug then
let solution = MAC_SOLUTION_FILE
#if LEGACY_FRAMEWORK
ExplicitRestore solution
// somehow, msbuild doesn't restore the frontend dependencies (e.g. Xamarin.Forms) when targetting
// the {LINUX|MAC}_SOLUTION_FILE below, so we need this workaround. TODO: just finish migrating to MAUI(dotnet restore)
NugetRestore solution
#endif
MSBuildRestoreAndBuild solution

Expand All @@ -302,7 +309,9 @@ let JustBuild binaryConfig maybeConstant: Frontend*FileInfo =
if FsxHelper.AreGtkLibsPresent Echo.All then
let solution = LINUX_SOLUTION_FILE
#if LEGACY_FRAMEWORK
ExplicitRestore solution
// somehow, msbuild doesn't restore the frontend dependencies (e.g. Xamarin.Forms) when targetting
// the {LINUX|MAC}_SOLUTION_FILE below, so we need this workaround. TODO: just finish migrating to MAUI(dotnet restore)
NugetRestore solution
#endif
MSBuildRestoreAndBuild solution

Expand Down Expand Up @@ -367,6 +376,10 @@ let GetPathToBackend () =
Path.Combine (FsxHelper.RootDir.FullName, "src", BACKEND)

let MakeAll (maybeConstant: Option<string>) =
#if LEGACY_FRAMEWORK
if not FsxHelper.NugetExe.Exists then
Network.DownloadNugetExe FsxHelper.NugetExe
#endif
let buildConfig = BinaryConfig.Debug
let frontend,_ = JustBuild buildConfig maybeConstant
frontend,buildConfig
Expand Down

0 comments on commit 4753743

Please sign in to comment.