Makefile for C# console programs - c#

How can I write a Makefile (gnu make) to compile a C# console project that has several files. I understand that there are other build tools, but my course requirements force me to submit a makefile.

You can simply use the compiler for the C#, with providing right arguments to it.
Here you can find examples
According to MSDN:
If you are working on a computer that only has the Windows Software Development Kit (SDK),
you can use the C# compiler at the command line if you use the SDK Command Prompt, which is
available from the Microsoft .NET Framework SDK menu option.
Or simply install the .NET Framework (thank to the #Alexei Levenkov).

If you have a Visual Studio installed just create a batch file and call
devenv your_project_complete_path
Or use MsBuild as provided in sample.
or use csc as provided in sample.

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.

Autocomplete for visual studio code not working for C#/Unity

I have just begun trying to learn C# with Unity. I'm following guides and tutorials. In these guides I see auto completions that my visual studio code is not showing me.
For example, in one video I see the following auto-completion:
On my own installation, I see the following:
Note that the auto-completion is not hinting Destroy. Other methods/functions such as GetComponent are also not auto-completed.
I believe that the correct folder is opened in VSC.
Visual studio code is set as my default editor in unity as per this question.
I have installed the .Net Core Extension Pack, which includes the C# extension pack for VSC. What am I missing?
Enabling code completion (For recent versions of Unity)
If you are installing VS Code for the first time, you might be missing targeting packs required for Unity's code-completion (IntelliSense) in VS Code.
Targeting pack download links:
• Windows: .NET Framework 4.6 Targeting Pack
Download Link: https://www.microsoft.com/download/details.aspx?id=48136
• macOS: Download .NET SDK
Download link: https://dotnet.microsoft.com/download
Steps:
Stop VS Code or Unity running.
Download and install the targeting pack for your targeted framework version / preferred version from one of the above links.
Start Unity.
Create and/or open an existing script in VS Code, through Unity, and you should now see code completions.
Reference: https://code.visualstudio.com/docs/other/unity

How to use Xamarin without the IDE?

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.

How can I get/run the 'gsharp' GUI wrapper for the csharp REPL in Mono?

Mono's C# REPL has on its page this bit of info:
A GUI version of this tool is called gsharp and is available when you install the mono-tools package
The same bit of info is mentioned in the Mono 2.2 release notes.
However, while I've installed the 30-day trial of mono-tools (vsix for VS2010), and the normal Mono for Windows package (2.10.8), I don't see anything in either that lets me open the window from the screen shot "C# InteractiveBase Shell". I also can't find any files on my disk (after installing both) starting with 'gsharp'
Did 'gsharp' move somewhere else?
I know the source is available as part of the mono-tools repo # https://github.com/mono/mono-tools/tree/master/gsharp, but just trying to find a 'release build' to use instead if possible. :)
Mono-tools for Visual Studio is a former product of Novell, which is discontinued (which Xamarin doesn't offer either).
I recommend you try to install Mono for Windows official bundle from http://www.mono-project.com/ If that installer doesn't include it, I recommend you compile mono-tools yourself, shouldn't be very hard with cygwin or mingw32.
PS: Note, "Mono tools for Visual Studio" and the "mono-tools" module (https://github.com/mono/mono-tools) are two different things.
(BTW, Mono 2.2 is very old. Only accept Mono 2.10.x or higher nowadays)

Packaging a .NET Application So It Will Run On A Computer Without .NET

I have been recently trying to deploy a C# application on a computer that does not have .NET installed.
I know that there have been many questions around the same topic here on StackOverflow. Here are a few of them, of which I read the responses to all:
Packaging up the .net framework with a .net application deployment
Run a .net application without installing .net client profile?
Run C# windows application in windows XP without installing .NET Framework
So all of the responses to the above questions state that it is impossible without specific software, etc. One software mentioned was the Salamander .NET Linker. The only problem with that is that I cannot seem to be able to run the application after it has been processed by Salamender. I understand that this in itself is impossible, as it requires the .NET virtual machine to run. However, in the past, I have made Java applications and along with them, I shipped the entire JVM. Surprisingly, they still worked. So the reason why this is not a duplicate of the above questions is because my true question is:
What items of the .NET framework would I need to package? If I do manage to package all, would placing them in the same directory as the application I'm running allow the application to run?
I found one solution to this, the Microsoft .NET Redist Package. The only problem with this is that it has a GUI of its own. Aside from that, it would be a perfect fit. So, could anyone tell me one of two things:
Is there a command-line .NET package, and if so, where do I download it?
If there isn't, or it would be impractical to do so, approximately what directories would I need to copy from the .NET installations?
I understand that these files and directories are system specific, and that my .NET installation may not work on your computer, but if C# is like Java, then this should be achievable. Is it? Size is not a limitation, it does not matter to me whether or not the application and all its files is 1GB, or if it is only 1MB.
If in case there is no other solution, I used Dependency Walker to check all the dependencies of my program. If I were to package most of them, would my application, in theory, work?
For .NET, you really must just install the appropriate .NET framework. The .NET framework installation does include command line options to allow for silent installs, such as:
dotnetfx35.exe /q /norestart
For details on the command line options, see the options for 3.5 and for .NET 4.0.
That being said, most installation packages will handle these details for you as part of the installation. Using a decent installer will take care of this dependency automatically.
Depending on the pieces of the .NET Framework you need, you can use Mono. It supports shipping the runtime without installing just like you would a JVM, or you can statically link against the binaries to create a native executable .
If you are planning to deploy your application (and presuming the setup process doesn't need to be too complex), you can simply create a Setup project in Visual Studio and then bootstrap the prerequisites (.NET framework, and other stuff you think you might need).
You can follow the steps described in these MSDN articles:
How to create a Setup project in Visual Studio
How to add prerequisites to a Setup project
A walkthrough is given in this CodeProject article.
For more complex deployment scenarios (such as installing device drivers along your app, or better localization support), I would recommend looking into WiX (Windows Installer XML) toolset. It's a toolset that builds Windows installation packages, which you configure using XML files inside Visual Studio. WiX also supports various bootstrapping scenarios.
This page covers the differences between VS Setup projects, WiX, and InstallShield.

Categories