How to use Xamarin without the IDE? - c#

I want to write an iOS app in C# with Xamarin and MonoTouch. I want to use Vim and Z shell instead of Xamarin Studio. However, I can't find much documentation on how to build from the command-line.
The documentation for the mtouch command says you have to pass an assembly as an argument, but how do I create that assembly?

The command line compilers that Mono provides are mcs, gmcs, and dmcs. For Mono 2.10.x and earlier, these are for C# 1.0, C# 2.0, and C# 4.0, respectively; for Mono 3.0.x, mcs defaults to the most recent version, and you have to select earlier language/runtime versions with the -langversion and -sdk options. The dmcs and gmcs commands in 3.0.x are scripts that call mcs with the appropriate -sdk option.
I am not sufficiently familiar with Xamarin.iOS to know how the libraries are laid out, but the -lib option allows you to tell the compiler about additional directories containing .dll assemblies and -r allows you to reference a specific assembly. The compiler will build a .exe assembly by default; use -target:library or -t:library to build a .dll one instead. The -help option will give you a list of all options.
You can use whatever build system you prefer from the command line. If you need to process MSBuild project files, then xbuild can handle them, but make, cmake, scons work fine, too, and are probably preferable to editing .sln files in Vim. You may still have to figure out dependencies yourself if they aren't obvious and if you have a complex project with multiple assemblies (the compiler is fast enough that you can just recompile everything for small single-assembly projects).
Note that I am not using Mono for this myself, but primarily for command line projects on OS X/Linux, so the above may be missing some subtle details related to building mtouch-ready assemblies for iOS.

Related

How to compile .g4 to .cs?

I reread all documentations but still didn't get what exactly do I need to do. Please explain step by step what do I need to do to set up work with Antlr in VS2019 (for C#) and how can I compile .g4 to .cs after. Do I need to install Antlr4 or Antlr4.Runtime or Antlr4.Runtime.Standard? Do I need to download "antlr-4.8-complete.jar" file from official site? If so, what should I do with it after? In general, as you can see, I'm confused in it.
I recommend this way--not because I wrote the software--but because it is easy and uses the most up-to-date release of Antlr:
Install the NET SDK (aka "dotnet.exe").
dotnet new -i Antlr4BuildTasks.Templates
dotnet new antlr
dotnet build
dotnet run
You can then open VS2019 or VSCode on the .csproj. See Antlr4BuildTasks.Templates. It uses Antlr4BuildTask for building. You don't need to install Java nor Antlr--it includes a copy of the Java JRE and Antlr. But, you will need connectivity to NuGet.org.
If for whatever reason you need to generate the .cs files outside of a build, then you can type it in from a shell:
java -jar ~/Downloads/antlr-4.8-complete.jar -Dlanguage=CSharp *.g4
Note, Antlr4.Runtime.Standard is the current Antlr runtime for C# as a netstandard1.3;net35 package. Antlr4.Runtime is Harwell's port of the entire Antlr Java code and runtime v4.6.6 to C#, and, as far as I know, it is not being maintained. There is a tool in that package that is the equivalent to the Java-based Antlr tool, so you can use that in a similar way. But, it is roughly 3 years behind the current release v4.8--soon to be v4.9. The Antlr4BuildTasks package I wrote is a modification of Harwell's package, but instead calls the Java-based Antlr tool.
Support within an editor for Antlr in VS2019, VSCode, or what have you, for syntactic or semantic highlighting, goto refs, goto def, etc., should be considered separate from the build of your app. Harwell's extension is for VS2017. For VSCode, you have the choice of Mike's vscode-antlr or my LSP-based tool Antlrvsix-vscode. For VS2019, you can use my extension Antlrvsix, or one of the few unsupported and very old extensions. Or, you can skip all that, and just edit it as text.

ASP.NET sass/scss compilation at run-time and at compile-time?

I am searching for a solution for compiling my .scss files at run-time and at compile-time.
The reason I need both is that our designers work on Macs and prefer the ease of having their .scss files compiled dynamically at run-time (especially during a development phase). On the other hand, I need compile-time support to validate that the SCSS compiles successfully during my build process. My goal is to fail a build if the SCSS doesn't compile.
I have found several libraries available on NuGet, however, minor flaws in each of them are holding me back.
Is there a solution available for both of these scenarios?
Here's where my research has led me:
Run-time Support
BundleTransformer.SassAndScss via HttpHandler (works with Bourbon, albeit very slow)
Cassette.Sass (unable to compile Bourbon due to error)
Compile-time support:
Cassette.MSBuild (Does not appear to bundle SCSS files, only CSS)
Mindscape Web Workbench (Pro version apparently includes a command-line tool, however, documentation is very limited on the feature)
Others?
The Pro edition of the Mindscape Web Workbench includes a command-line tool for compiling at runtime. Currently, only the nightly build is capable of compiling Bourbon and Neat (one of my requirements).
Here is my pre-build event which is working great at the moment:
"C:\Program Files (x86)\Mindscape\Web Workbench\Command Line\wwcmd.exe"
"$(ProjectDir)scss\style.scss" /o:../css /style:compressed
UPDATE:
We decided to simply call SASS from a pre-build event as opposed to using Web Workbench.
call sass -C "$(ProjectDir)assets\scss\main.scss" "$(ProjectDir)assets\css\compiled\main.css" --style compressed
Check out SassAndCoffee. It's what Cassette is using and it embeds everything into a few assemblies.
Web Workbench on the other hand actually installs ruby and the sass gems to the file system in a very long folder path hidden beneath the current users directory, which is likely to be troublesome for a web application and with respect to security and permissions.
For ASP.NET Core you can use this package to compile scss at build time and it includes a watcher for debug-time and hot-reloading.
AspNetCore.SassCompiler
Sass Compiler Library for .NET Core 3.1/5.x./6.x without node.
https://github.com/koenvzeijl/AspNetCore.SassCompiler
# Package Manager
PM> Install-Package AspNetCore.SassCompiler
# .NET CLI
dotnet add package AspNetCore.SassCompiler

Understanding .NET Assembly Reference Differences

I have two nearly identical DLLS (for the same open source project) - one was pre-compiled, and one was compiled locally by my own compiler (Xamarin Studio/Mono).
The DLL I compiled isn't working with the application that's supposed to be using it (while the pre-built one does), so I grabbed a decompiler to see if I can track down any differences (file sizes were slightly different):
I suspect the reference differences might be the problem. The TOP one is the manually compiled dll. How can I resolve this and make the references identical to the bottom dll's? I've tried using the Mono/.NET 3.5 option in the settings, but it resulted in errors complaining about default parameter specifiers in a bunch of places, so it seems as if it's meant to be compiled w/4.0. Here's a cap of the build settings options (only the Mono/.NET 4.0 option works):
What's causing the differences in assembly references?
Microsoft introduces the multi-targeting feature in its C# compiler, so that C# 4/5 compiler (csc.exe) can generate .NET 2.0/3.0/3.5 compatible assemblies. That's how the pre-compiled assembly comes from.
Unfortunately it is a long time issue for MonoDevelop, that it does not support such multi-targeting. For example, you cannot choose Mono/.NET 3.5 and expect Xamarin Studio/MonoDevelop to use the latest mcs compiler. It always uses the one for .NET 3.5 profile, and fails to compile if you use any C# 4/5 syntax.
You might try to use xbuild at terminal to compile, as xbuild does support multi-targeting. However, you might come across xbuild issues, as it is not yet as capable as MSBuild.

Cross platform build script that can call MSBuild or Xbuild depending on environment?

I have a simple .Net console app which has only framework dependencies. It can compile fine with either MSBuild on windows or Mono/XBuild on linux. It is part of a larger project, which has a python build script. Is there any simple way to determine the most suitable build engine (msbuild/xbuild) and use that?
In other words, I have a 'build.py' and I want that to call xbuild or msbuild as needed.
Far easier would be to write a small shell script for Linux or OSX that ran xbuild but was called msbuild. The arguments are the same I think.

How do I add a .NET Runtime in Edit->Prefrences?

Ok I am using Windows and have .Net 3.5 and the Mono 2.6 frameworks installed. I also have installed MonoDevelop and plan on using it. I just need to know if I am setup to use the Mono runtime.
All my projects have build options for Mono/Microsoft.NET 3.5, but in Edit->Prefrences->.NET Runtimes, all I see is Microsoft.NET. How do I add the Mono runtime to this list and make it default? Or do I even need to do this? I would think I would have to since our projects will be run on Linux, but not sure how to 'make sure' I am actually using Mono and not just .NET?
Mono should show up simply by virtue of being installed. You can try reinstalling Mono to see if that helps.
If not, click the "Add" button on the Edit->Preferences->.Net Runtimes page and choose where you installed Mono to, generally it will be something like:
C:\Program Files\Mono-2.6.1
If you want it to be the default, click "Set as Default" while it's highlighted and it should turn bold, indicating it is now the default. There is also a combobox on the main MD toolbar if you want a quicker way of switching between runtimes.
You shouldnt HAVE to build using Mono's compiler on Windows to have your code run on Linux.
As per answers on Performance: Compile in CS, Run in mono on windows and linux, you can compile with any compiler and run with any runtime because the compiled binary is in an Intermediate Language
You just have to be certain that your code, and the libraries that it uses, do not make operating system specific calls, P/Invoke unmanaged DLL's, or make calls to functions that are incomplete in Mono (mind you, these are getting rare)

Categories