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 馃槙
Thanks for adding this.
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
@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
@ferventcoder That already exists in master: https://github.com/chocolatey/choco/blob/master/lib/NAnt/NAnt.exe.config#L3263-L3266
Looks like I upgraded that bit then. Thanks, had not realized it! Hmmm. Other things to consider then.
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.
+1 for this :-)
+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.
This draws Linux/Docker based CI almost useless, since the latest Mono 3.X Docker image is based in wheezy, which reached EOL.
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
Does Chocolately work on .NET Core, or does it require Mono?
Most helpful comment
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.