Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build fails on newer Mono versions #1020

Closed
Daniel15 opened this issue Oct 16, 2016 · 12 comments
Closed

Build fails on newer Mono versions #1020

Daniel15 opened this issue Oct 16, 2016 · 12 comments
Assignees
Labels
5 - Released Bug Customer Improvement NO RELEASE NOTES Should not be included in the release notes - not enhancing or fixing end product. Priority_LOW
Milestone

Comments

@Daniel15
Copy link

Daniel15 commented Oct 16, 2016

Chocolately successfully builds on a pretty old version of Mono (as can be seen in the Travis build), but it fails on newer 4.x versions of Mono. I tried fixing this myself but ran into an issue.

The first issue was that Mono no longer has its libraries in /usr/lib/mono/4.0, they all moved to 4.5 when Mono added support for .NET Framework 4.5 as a drop-in replacement for 4.0 (runtime version is still 4.0.30319 but the assemblies are in /usr/lib/mono/4.5). I fixed that with the following patch:

diff --git a/build.sh b/build.sh
index 648b60c..719b2f4 100755
--- a/build.sh
+++ b/build.sh
@@ -25,7 +25,6 @@ displayUsage $1
 export PKG_CONFIG_PATH=/opt/local/lib/pkgconfig:/Library/Frameworks/Mono.framework/Versions/Current/lib/pkgconfig:$PKG_CONFIG_PATH

 #mono ./lib/NAnt/NAnt.exe /logger:"NAnt.Core.DefaultLogger" /nologo /quiet /f:"$(cd $(dirname "$0"); pwd)/.build/default.build" /D:build.config.settings="$(cd $(dirname "$0"); pwd)/.uppercut" /D:microsoft.framework="mono-3.5" $*
-mono --runtime=v4.0.30319 ./lib/NAnt/NAnt.exe /logger:"NAnt.Core.DefaultLogger" /nologo /quiet /f:"$(cd $(dirname "$0"); pwd)/.build/default.build" /D:build.config.settings="$(cd $(dirname "$0"); pwd)/.uppercut" /D:microsoft.framework="mono-4.0" /D:run.ilmerge="false" /D:run.nuget="false" $*
+mono --runtime=v4.0.30319 ./lib/NAnt/NAnt.exe /logger:"NAnt.Core.DefaultLogger" /nologo /quiet /f:"$(cd $(dirname "$0"); pwd)/.build/default.build" /D:build.config.settings="$(cd $(dirname "$0"); pwd)/.uppercut" /D:microsoft.framework="mono-4.5" /D:run.ilmerge="false" /D:run.nuget="false" $*

 #/quiet /nologo /debug /verbose /t:"mono-4.0"
diff --git a/lib/NAnt/NAnt.exe.config b/lib/NAnt/NAnt.exe.config
index b590ff0..74f275e 100644
--- a/lib/NAnt/NAnt.exe.config
+++ b/lib/NAnt/NAnt.exe.config
@@ -2342,13 +2342,13 @@
                     </tasks>
                 </framework>
                 <framework
-                    name="mono-4.0"
+                    name="mono-4.5"
                     family="mono"
-                    version="4.0"
-                    description="Mono 4.0 Profile"
+                    version="4.5"
+                    description="Mono 4.5 Profile"
                     sdkdirectory="${toolDirectory}"
                     frameworkdirectory="${toolDirectory}"
-                    frameworkassemblydirectory="${path::combine(frameworkAssemblyDirectory, 'mono/4.0')}"
+                    frameworkassemblydirectory="${path::combine(frameworkAssemblyDirectory, 'mono/4.5')}"
                     clrversion="4.0.30319"
                     clrtype="Desktop"
                     vendor="Mono"
@@ -2379,6 +2379,9 @@
                             </strict>
                         </modes>
                     </runtime>
+                    <reference-assemblies basedir="${path::combine(frameworkAssemblyDirectory, 'mono/4.5')}">
+                        <include name="*.dll" />
+                    </reference-assemblies>
                     <reference-assemblies basedir="${path::combine(frameworkAssemblyDirectory, 'mono/4.0')}">
                         <include name="*.dll" />
                     </reference-assemblies>
@@ -2400,6 +2403,7 @@
                         <include name="extensions/common/2.0/**/*.dll" />
                     </task-assemblies>
                     <tool-paths>
+                        <directory name="${path::combine(frameworkAssemblyDirectory, 'mono/4.5')}" />
                         <directory name="${path::combine(frameworkAssemblyDirectory, 'mono/4.0')}" />
                         <directory name="${path::combine(frameworkAssemblyDirectory, 'mono/3.5')}" />
                         <directory name="${path::combine(frameworkAssemblyDirectory, 'mono/2.0')}" />
@@ -3004,13 +3008,13 @@
                     </tasks>
                 </framework>
                 <framework
-                    name="mono-4.0"
+                    name="mono-4.5"
                     family="mono"
-                    version="4.0"
-                    description="Mono 4.0 Profile"
+                    version="4.5"
+                    description="Mono 4.5 Profile"
                     sdkdirectory="${toolDirectory}"
                     frameworkdirectory="${toolDirectory}"
-                    frameworkassemblydirectory="${path::combine(prefix, 'lib/mono/4.0')}"
+                    frameworkassemblydirectory="${path::combine(prefix, 'lib/mono/4.5')}"
                     clrversion="4.0.30319"
                     clrtype="Desktop"
                     vendor="Mono"
@@ -3033,6 +3037,9 @@
                             </strict>
                         </modes>
                     </runtime>
+                    <reference-assemblies basedir="${path::combine(prefix, 'lib/mono/4.5')}">
+                        <include name="*.dll" />
+                    </reference-assemblies>
                     <reference-assemblies basedir="${path::combine(prefix, 'lib/mono/4.0')}">
                         <include name="*.dll" />
                     </reference-assemblies>
@@ -3055,6 +3062,7 @@
                     </task-assemblies>
                     <tool-paths>
                         <directory name="${toolDirectory}" />
+                        <directory name="${path::combine(prefix, 'lib/mono/4.5')}" />
                         <directory name="${path::combine(prefix, 'lib/mono/3.5')}" />
                         <directory name="${path::combine(prefix, 'lib/mono/2.0')}" />
                         <directory name="${path::combine(prefix, 'lib/mono/1.0')}" />
@@ -3067,7 +3075,7 @@
                         </if>
                         <property name="resgen.supportsexternalfilereferences" value="false" />
                         <property name="prefix" value="${pkg-config::get-variable('mono', 'prefix')}" />
-                        <property name="toolDirectory" value="${path::combine(prefix, 'lib/mono/4.0')}" />
+                        <property name="toolDirectory" value="${path::combine(prefix, 'lib/mono/4.5')}" />
                     </project>
                     <tasks>
                         <task name="al">

However, now I'm hitting this error, and I can't figure out how to proceed:

daniel@debian:/media/sf_src/choco$ ./build.sh -v
Buildfile: file:///media/sf_src/choco/.build/default.build
Target framework: Mono 4.5 Profile
Base Directory: /media/sf_src/choco/.build.
Target(s) specified: go

 [property] Property "build.config.settings" already exists, and "overwrite" is set to false.
  [include] Including file /media/sf_src/choco/.uppercut.
 [property] Property "run.ilmerge" already exists, and "overwrite" is set to false.
  [include] Including file /media/sf_src/choco/.build/default.build.settings.
 [property] Property "project.name" already exists, and "overwrite" is set to false.
 [property] Property "repository.path" already exists, and "overwrite" is set to false.
 [property] Property "company.name" already exists, and "overwrite" is set to false.
 [property] Property "folder.build_scripts" already exists, and "overwrite" is set to false.
 [property] Property "folder.build_scripts_custom" already exists, and "overwrite" is set to false.
  [include] Including file /media/sf_src/choco/.build/csharp.functions.
   [script] Adding assembly NAnt.Core
   [script] Adding assembly System

BUILD FAILED

Compilation failed:
/tmp/39dacb4f/4b515f02.0.cs(18,43) : error CS0246: The type or namespace name `Task' could not be found. Are you missing `System.Threading.Tasks' or `NAnt.Core' using directive?
/tmp/39dacb4f/4b515f02.0.cs(29,37) : error CS0115: `nant4d22b3c1168943b4a1d049edf98a8962.ResultsProcessTask.ExecuteTask()' is marked as an override but no suitable method found to override
// ------------------------------------------------------------------------------
//  <autogenerated>
//      This code was generated by a tool.
//      Mono Runtime Version: 4.0.30319.17020
//
//      Changes to this file may cause incorrect behavior and will be lost if
//      the code is regenerated.
//  </autogenerated>
// ------------------------------------------------------------------------------

using NAnt.Core;
using NAnt.Core.Attributes;
using System;
using System.Collections;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Text;



[FunctionSet("script", "script")]
public class nant4d22b3c1168943b4a1d049edf98a8962 : NAnt.Core.FunctionSetBase {


        [TaskName("results")]
        public class ResultsProcessTask : Task
        {
            private string _display;

            [TaskAttribute("display", Required = true)]
            public string Display
            {
                get { return _display; }
                set { _display = value; }
            }

            protected override void ExecuteTask()
            {
                if (platformIsWindows())
                    ExecuteProcess(CombinePaths(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles),"Internet Explorer","iexplore.exe"), Display);
                else
                    ExecuteProcess(Display);
            }

            protected string CombinePaths(params string[] paths)
            {
                string combinedPath = string.Empty;

                foreach (string path in paths)
                {
                    combinedPath = Path.Combine(combinedPath, path);
                }

                return combinedPath;
            }

            protected void ExecuteProcess(string file)
            {
                ProcessStartInfo psi = new ProcessStartInfo(file, "");
                using (Process p = new Process())
                {
                    p.StartInfo = psi;
                    p.Start();
                }
            }

            protected void ExecuteProcess(string process, string arguments)
            {
                ProcessStartInfo psi = new ProcessStartInfo(Path.GetFullPath(process), arguments);
                psi.UseShellExecute = false;
                psi.RedirectStandardOutput = false;
                psi.CreateNoWindow = false;

                using (Process p = new Process())
                {
                    p.StartInfo = psi;
                    p.Start();
                }

            }

            protected bool platformIsWindows()
            {
                PlatformID platform = Environment.OSVersion.Platform;
                return !(platform.Equals(PlatformID.Unix) || platform.Equals(PlatformID.MacOSX));
            }
        }


    public nant4d22b3c1168943b4a1d049edf98a8962(NAnt.Core.Project project, NAnt.Core.PropertyDictionary propDict) :
            base(project, propDict) {
    }
}

I could get past "The type or namespace name Task could not be found." error by explicitly referencing the right namespace (NAnt.Core.Task rather than just Task), but that just resulted in even more errors:

Compilation failed:
/tmp/17fc87fc/6f304db5.0.cs(13,2) : error CS0246: The type or namespace name `FunctionSet' could not be found. Are you missing an assembly reference?
/tmp/17fc87fc/6f304db5.0.cs(17,10) : error CS0246: The type or namespace name `TaskName' could not be found. Are you missing an assembly reference?
/tmp/17fc87fc/6f304db5.0.cs(22,14) : error CS0246: The type or namespace name `TaskAttribute' could not be found. Are you missing an assembly reference?
/tmp/17fc87fc/6f304db5.0.cs(32,49) : error CS0103: The name `Environment' does not exist in the current context
/tmp/17fc87fc/6f304db5.0.cs(43,36) : error CS0103: The name `Path' does not exist in the current context
/tmp/17fc87fc/6f304db5.0.cs(51,17) : error CS0246: The type or namespace name `ProcessStartInfo' could not be found. Are you missing `System.Diagnostics' using directive?
/tmp/17fc87fc/6f304db5.0.cs(52,24) : error CS0246: The type or namespace name `Process' could not be found. Are you missing `System.Diagnostics' using directive?
/tmp/17fc87fc/6f304db5.0.cs(61,17) : error CS0246: The type or namespace name `ProcessStartInfo' could not be found. Are you missing `System.Diagnostics' using directive?
/tmp/17fc87fc/6f304db5.0.cs(62,17) : error CS0841: A local variable `psi' cannot be used before it is declared
/tmp/17fc87fc/6f304db5.0.cs(63,17) : error CS0841: A local variable `psi' cannot be used before it is declared
/tmp/17fc87fc/6f304db5.0.cs(64,17) : error CS0841: A local variable `psi' cannot be used before it is declared
/tmp/17fc87fc/6f304db5.0.cs(66,24) : error CS0246: The type or namespace name `Process' could not be found. Are you missing `System.Diagnostics' using directive?
/tmp/17fc87fc/6f304db5.0.cs(76,17) : error CS0246: The type or namespace name `PlatformID' could not be found. Are you missing `System' using directive?
/tmp/17fc87fc/6f304db5.0.cs(77,26) : error CS0841: A local variable `platform' cannot be used before it is declared

I can't work out why this is happening, as all the correct using statements are at the top of the generated file 😕

@ferventcoder
Copy link
Member

Thanks for adding this.

@Daniel15
Copy link
Author

Confirmed that the build fails for all Mono versions 4.0 and above, which is when they switched to .NET Framework 4.5 and removed the legacy assemblies. Even though I think I updated NAnt.exe.config correctly, I suspect something is still relying on legacy Mono 3.x behaviour

@ferventcoder
Copy link
Member

@Daniel15

I think you missed the startup section, allowing Nant to run under newer assemblies

<startup>
 +        <!-- .NET Framework 4.5.2 -->
 +        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2"/>
 +        <!-- .NET Framework 4.5 -->
 +        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>

See https://github.com/chocolatey/choco/pull/459/files#diff-138919a4610603c090b4dc1530347f2bR3263

@Daniel15
Copy link
Author

@ferventcoder
Copy link
Member

Looks like I upgraded that bit then. Thanks, had not realized it! Hmmm. Other things to consider then.

@ghost
Copy link

ghost commented Aug 3, 2017

Just stumbled onto this issue -- I see it's marked low priority but would love if it could be up'd in priority. My team would like to develop locally, push to a version controlled system and then have a post commit hook update the packages on the actual repository; the problem is that the server is linux so it needs to be able to build the packages from there.

@ferventcoder ferventcoder modified the milestones: 0.10.8, 0.10.x Aug 8, 2017
@ferventcoder ferventcoder self-assigned this Aug 8, 2017
@ferventcoder ferventcoder modified the milestones: 0.10.8, 0.10.9, 0.10.10 Aug 27, 2017
@mwallner
Copy link
Member

+1 for this :-)

@petemounce
Copy link

petemounce commented Feb 15, 2018

+1 for this. My use case is that I want to enable an open source project, bazel, to publish the chocolatey package for their release via their existing release process, which runs on Linux and does not involve Windows.

TheCakeIsNaOH added a commit to TheCakeIsNaOH/choco that referenced this issue Aug 17, 2019
TheCakeIsNaOH added a commit to TheCakeIsNaOH/choco that referenced this issue Oct 4, 2019
This changes the docker container to use code_drop folder instead of the build_output folder.  The zip.sh script uses the code_drop rather then build_output, and the docker container should follow what format the zip has.

The wrapper script also changes due to choco.exe being one more folder down.
TheCakeIsNaOH added a commit to TheCakeIsNaOH/choco that referenced this issue Oct 4, 2019
This environment variable is needed to for docker choco to not output a warning that it cannot find the chocolatey lib directory.
TheCakeIsNaOH added a commit to TheCakeIsNaOH/choco that referenced this issue Oct 4, 2019
…n linux

The [WindowsOnly] was not working, so the platform exclude was added. This removes the windows only altogether.
TheCakeIsNaOH added a commit to TheCakeIsNaOH/choco that referenced this issue Nov 1, 2019
ferventcoder pushed a commit that referenced this issue Mar 25, 2020
Add Mono framework for .NET 4.5 as newer versions of Mono
do not have .NET 4.0 anymore.
ferventcoder pushed a commit that referenced this issue Mar 25, 2020
Update Dockerfile and Travis to Mono v5.20.1. Remove mono-gmcs
from what is installed for Travis.

Remove mono-gmcs as it is obsolete and no longer available with
Mono 5.
ferventcoder pushed a commit that referenced this issue Mar 25, 2020
Change the docker container to use `code_drop` folder instead of the
`build_output` folder.  The zip.sh script uses the `code_drop` rather
than `build_output`, so the docker container should follow the same
format the zip does.

Account for the path change for choco.exe in the wrapper script.
ferventcoder pushed a commit that referenced this issue Mar 25, 2020
The ChocolateyInstall environment variable is needed to for docker
choco to not output a warning that it cannot find the Chocolatey
lib directory and use a different path for packages depending on where
the command is run from. Add the environment variable to make it available
in the right location.
ferventcoder pushed a commit that referenced this issue Mar 25, 2020
Previously, Windows only tests were ignored based on a build compilation
symbol `__MonoCS__`. This allowed skipping (ignoring) those tests
easily. However newer versions of Mono simply don't use that symbol
anymore and the testing aspect does not ignore those tests, ultimately
causing them to fail when run in a non-Windows environment.

Switch over to using platform that only includes Windows. This will
exclude Windows only tests from running on Unix, Linux and MacOS.
ferventcoder added a commit that referenced this issue Mar 25, 2020
Unfortunately, it appears like platform exclusions go by the actual
name of "Platform" and attempting to inherit the attribute is ignored
by NUnit when selecting platforms to exclude for testing.

Add those directly for now until a better alternative is available.
ferventcoder added a commit that referenced this issue Mar 25, 2020
* pr1827:
  (GH-1020) Direct platform only for windows tests
  (GH-1020) WindowsOnly tests by platform, not ignore
  (GH-1020) Docker add ChocolateyInstall Env Var
  (GH-1020) Docker use code_drop instead of build_output
  (doc) Update mono installation instructions in README
  (GH-1020) Dockerfile and Travis to Mono 5.20.1
  (GH-1020) Add mono-4.5 configuration
ferventcoder added a commit that referenced this issue Mar 25, 2020
* stable:
  (GH-1020) Direct platform only for windows tests
  (GH-1020) WindowsOnly tests by platform, not ignore
  (GH-1020) Docker add ChocolateyInstall Env Var
  (GH-1020) Docker use code_drop instead of build_output
  (doc) Update mono installation instructions in README
  (GH-1020) Dockerfile and Travis to Mono 5.20.1
  (GH-1020) Add mono-4.5 configuration
@ferventcoder
Copy link
Member

This has just been merged to stable and master. See commits and merges in notes above this comment. Thanks for the patience in getting this over the line

ferventcoder added a commit that referenced this issue Mar 25, 2020
Missed part of the commit in 22fe302.
Ensure those brackets are there so the build is not failing.
ferventcoder added a commit that referenced this issue Mar 25, 2020
* stable:
  (GH-1020) fix build
@Daniel15
Copy link
Author

Does Chocolately work on .NET Core, or does it require Mono?

johnstevenson added a commit to johnstevenson/choco that referenced this issue Jun 20, 2020
* upstream/master: (21 commits)
  (doc) Changed cla links from clahub to cla-assistant
  (chocolateyGH-2055) remove logs/config folder in nupkg
  (version) 0.10.16-beta
  (chocolateyGH-2023) Install git in the docker container
  (chocolateyGH-1859) Fix error message for missing 32-bit URL
  (chocolateyGH-1859) Fix error message for missing 32-bit URL
  (chocolateyGH-2051) Fix: workingDirectory always replaced w/cacheLocation
  (chocolateyGH-1983) exit-on-reboot-detected environment variable
  (maint) update resharper settings
  (maint) formatting
  (chocolateyGH-1843) Fix: search exact all versions returns 1
  (chocolateyGH-1020) fix build
  (chocolateyGH-1020) Direct platform only for windows tests
  (chocolateyGH-1020) WindowsOnly tests by platform, not ignore
  (chocolateyGH-1020) Docker add ChocolateyInstall Env Var
  (chocolateyGH-1020) Docker use code_drop instead of build_output
  (doc) Update mono installation instructions in README
  (chocolateyGH-1020) Dockerfile and Travis to Mono 5.20.1
  (chocolateyGH-1020) Add mono-4.5 configuration
  Add missing start of comment block
  ...
@gep13
Copy link
Member

gep13 commented Apr 15, 2021

@Daniel15 at the minute, Chocolatey requires mono to run on, it doesn't target .NET Core.

@gep13 gep13 added NO RELEASE NOTES Should not be included in the release notes - not enhancing or fixing end product. and removed Up For Grabs labels May 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
5 - Released Bug Customer Improvement NO RELEASE NOTES Should not be included in the release notes - not enhancing or fixing end product. Priority_LOW
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants