MonoDevelop Error: Unknown MSBuild failure. Please try building the project again - c#

Just installed MonoDevelop and I tried to compile a simple "Hello World".
Code I used:
using System;
public class HelloWorld
{
static public void Main ()
{
Console.WriteLine ("Hello Mono World");
}
}
The error that I get is :
EmptyCSharpFile.csproj(1,1): Error: Unknown MSBuild failure. Please try building the project again (EmptyCSharpFile)
My system info:
Ubuntu 16.04 LTS , updated
The MonoDevelop and mono are freshly installed.
Mono JIT compiler version 5.0.1.1
MonoDevelop Version 5.10
I can use mcs and run it but can't use monodevelop to run it.
I did read these similar topics but no response yet:
MonoDevelop Failure "Unknown MSBuild Failure" on Linux ;
C# compile Unknown MSBuild error MonoDevelop Linux ; https://askubuntu.com/questions/73630/could-not-obtain-c-compiler-error-when-using-monodevelop

I too had the same problem when I first installed it , I assume you went straight to file -> new-> file-> general -> emptyc# file.
Instead of that, go to file->new-> solution from there choose Console C# project or simply press ctrl + shift + N choose next ,and give project name, by default the new project has a simple hello world program run it, this time it will work.(it worked for me)

Related

Xamarin iOS - "Native linking failed for .." with Static Library Bind

I'm trying to build an, only iOS, app but I get two errors:
linker command failed with exit code 1 (use -v to see invocation)
Native linking failed for '/Users/{name}/Desktop/{application name}/{application name}/obj/iPhone/Debug/device-builds/iphone8.1-11.1.2/mtouch-cache/arm64/libSomething.dll.dylib'. Please file a bug report at http://bugzilla.xamarin.com
I get these errors with a dll generated from a binding of a (native obj-c) static library with XCode 9.2
I'm using Visual Studio 7.2 with Xamarin.iOS 11.6.1.2
I fixed it.
The error was in the Static Library, was missing two classes.
I've added these two in XCode and then works.

MonoDevelop Failure "Unknown MSBuild Failure" on Linux

I just installed MonoDevelop on my Ubuntu machine, and attemtepted to run a hello world, just to test it out:
using System;
public class HelloWorld
{
static public void Main ()
{
Console.WriteLine ("Hello Mono World");
}
}
...but when building it gives an "Unknown MSBuild failure" error
I have tested Mono before using MonoDevelop and verified that it works.
This is most likely due to an error or errors during compilation, which oddly enough, MonoDevelop is not telling you.
Assuming you have mono itself installed, open a terminal and compile from there(source):
mcs HelloWorld.cs
I have had similar issue with a project that used to work - it seems error is in the package NUnit, however I have not yet found a solution for it - have a look at your packages, perhaps you find your issue there

Is it possible to use the Ubuntu Linux version of MonoDevelop 6.0 watch window to inspect local variables?

I am debugging a modified C# pure .NET CoreCLR Hello World application compiled with the Roslyn csc.exe compiler. The Hello World C# program is shown below:
using System;
namespace TestingMonoDevelop6.0
{
class MainClass
{
public static void Main(string[] args)
{
string value = "one";
Console.WriteLine("Hello World!");
}
}
}
This is the Roslyn csc.exe compiler directive and result:
Building TestingMonoDevelop6.0 (Debug|x86) Executing:
/home/venkat/roslyn/Binaries/Debug/csc.exe /noconfig /nostdlib
/debug:portable /out:/home/venkat/Caisse/Caisse/bin/Debug/Caisse.exe
/r:/home/venkat/Sandbox/Microsoft.CodeAnalysis.dll
/r:/home/venkat/Sandbox/Microsoft.Data.Sq
Microsoft (R) Visual C# Compiler version 42.42.42.42
Copyright (C) Microsoft Corporation. All rights reserved.
Program.cs(9,11): warning CS0219: The variable 'value' is assigned but its value is never used
---------------------- Done ----------------------
Build successful.
Here is the Ubuntu Linux 14.04 LTS mono version and path.
[mono-2015.12.15+14.05.01]venkat#clickit:~/monodevelop$ which mono
/opt/mono-2015.12.15+14.05.01/bin/mono
So, I was told that Monodevelop 6.0 would support Roslyn csc.exe compilation s month ago in the github.io.mono.monodevelop forum. My first question is how do we ask Monodevelop 6.0 to compile with the Roslyn csc.exe compiler?
When I create the following Monodevelop 6.0 C# custom build step on
Ubuntu : /home/venkat/roslyn/Binaries/Debug/csc.exe /noconfig
/nostdlib /debug:portable
/out:/home/venkat/December14/December14/bin/Debug/Program.exe
/r:/home/venkat/Sandbox/Microsoft.CodeAnalysis.dll
/r:/home/venkat/Sandbox/Microsoft.Data.Sqlite.dll
/r:/home/venkat/.dnx/packages/System.Collections/4.0.11-beta-23409/ref/dotnet/System.Collections.dll
/r:/home/venkat/.dnx/packages/System.Collections.NonGeneric/4.0.0/ref/dotnet/System.Collections.NonGeneric.dll
/r:/home/venkat/.dnx/packages/System.ComponentModel/4.0.1-beta-23516/ref/dotnet5.1/System.ComponentModel.dll
/r:/home/venkat/Sandbox/System.dll
/r:/home/venkat/.dnx/packages/System.Data.Common/4.0.1-beta-23516/ref/dotnet5.1/System.Data.Common.dll
/r:/home/venkat/.dnx/packages/System.Xml.ReaderWriter/4.0.10-beta-22816/lib/contract/System.Xml.ReaderWriter.dll
/r:/home/venkat/.dnx/packages/System.Xml.XmlDocument/4.0.0-beta-22816/lib/contract/System.Xml.XmlDocument.dll
/r:/home/venkat/.dnx/packages/Microsoft.CSharp/4.0.1-beta-23409/ref/dotnet/Microsoft.CSharp.dll
/r:/home/venkat/Sandbox/System.Runtime.dll
/r:/home/venkat/Sandbox/System.Xml.XDocument.dll
/r:/home/venkat/Sandbox/System.Xml.dll
/r:/home/venkat/Sandbox/System.Threading.Tasks.dll
/r:/home/venkat/Sandbox/System.Linq.dll
/r:/home/venkat/Sandbox/System.Xml.dll
/r:/home/venkat/Sandbox/mscorlib.dll Program.cs ,
it successfully compiles. When I start debugging the Roslyn generated executable and using the Monodevelop Watch window on i, I get the following error
message: Unknown variable i
when I set a breakpoint on the Console.WriteLine("Hello World!") line.
My third question is do I have to create a Custom Execute Step in
Monodevelop 6.0 for Linux referencing Corerun Program.exe instead of
mono Program.exe?
The answer to question 1, "how do we ask Monodevelop 6.0 to compile with the Roslyn csc.exe compiler?" is:
/home/venkat/roslyn/Binaries/Debug/csc.exe /noconfig
/nostdlib /debug:portable
/out:/home/venkat/December14/December14/bin/Debug/Program.exe
/r:/home/venkat/Sandbox/Microsoft.CodeAnalysis.dll
/r:/home/venkat/Sandbox/Microsoft.Data.Sqlite.dll
/r:/home/venkat/.dnx/packages/System.Collections/4.0.11-beta-23409/ref/dotnet/System.Collections.dll
/r:/home/venkat/.dnx/packages/System.Collections.NonGeneric/4.0.0/ref/dotnet/System.Collections.NonGeneric.dll
/r:/home/venkat/.dnx/packages/System.ComponentModel/4.0.1-beta-23516/ref/dotnet5.1/System.ComponentModel.dll
/r:/home/venkat/Sandbox/System.dll
/r:/home/venkat/.dnx/packages/System.Data.Common/4.0.1-beta-23516/ref/dotnet5.1/System.Data.Common.dll
/r:/home/venkat/.dnx/packages/System.Xml.ReaderWriter/4.0.10-beta-22816/lib/contract/System.Xml.ReaderWriter.dll
/r:/home/venkat/.dnx/packages/System.Xml.XmlDocument/4.0.0-beta-22816/lib/contract/System.Xml.XmlDocument.dll
/r:/home/venkat/.dnx/packages/Microsoft.CSharp/4.0.1-beta-23409/ref/dotnet/Microsoft.CSharp.dll
/r:/home/venkat/Sandbox/System.Runtime.dll
/r:/home/venkat/Sandbox/System.Xml.XDocument.dll
/r:/home/venkat/Sandbox/System.Xml.dll
/r:/home/venkat/Sandbox/System.Threading.Tasks.dll
/r:/home/venkat/Sandbox/System.Linq.dll
/r:/home/venkat/Sandbox/System.Xml.dll
/r:/home/venkat/Sandbox/mscorlib.dll Program.cs
,
The answer to question 2 , "When I start debugging the Roslyn generated executable and using the Monodevelop Watch window on i, I get the following error
message: Unknown variable i
when I set a breakpoint on the Console.WriteLine("Hello World!") line.". is that the mono runtime is mdb bug free and that the Roslyn compiler on non-Window OS can produce only portable pdb's. There is an reproducible Macintosh open bug at https://bugzilla.xamarin.com/ under XamarinStudio->Debugger component.Please see https://gitter.im/dotnet/roslyn.
The answer to question 3, do I have to create a Custom Execute Step in Monodevelop 6.0 for Linux referencing Corerun Program.exe instead of mono Program.exe? Yes. In fact, if one wishes to target CoreCLR, they should use the Roslyn csc.exe compiler.

How to compile c# in Microsoft's new Visual Studio Code?

I have installed the preview version of Microsoft's new code editor "Visual Studio Code". It seems quite a nice tool!
The introduction mentions you can program c# with it, but the setup document does not mention how to actually compile c# files.
You can define "mono" as a type in the "launch.json" file, but that does not do anything yet. Pressing F5 results in: "make sure to select a configuration from the launch dropdown"...
Also, intellisense is not working for c#? How do you set the path to any included frameworks?
Launch.json:
"configurations": [
{
// Name of configuration; appears in the launch configuration drop down menu.
"name": "Cars.exe",
// Type of configuration. Possible values: "node", "mono".
"type": "mono",
// Workspace relative or absolute path to the program.
"program": "cars.exe",
},
{
"type": "mono",
}
Since no one else said it, the short-cut to compile (build) a C# app in Visual Studio Code (VSCode) is SHIFT+CTRL+B.
If you want to see the build errors (because they don't pop-up by default), the shortcut is SHIFT+CTRL+M.
(I know this question was asking for more than just the build shortcut. But I wanted to answer the question in the title, which wasn't directly answered by other answers/comments.)
Intellisense does work for C# 6, and it's great.
For running console apps you should set up some additional tools:
ASP.NET 5; in Powershell: &{$Branch='dev';iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.ps1'))}
Node.js including package manager npm.
The rest of required tools including Yeoman yo: npm install -g yo grunt-cli generator-aspnet bower
You should also invoke .NET Version Manager: c:\Users\Username\.dnx\bin\dnvm.cmd upgrade -u
Then you can use yo as wizard for Console Application: yo aspnet Choose name and project type. After that go to created folder cd ./MyNewConsoleApp/ and run dnu restore
To execute your program just type >run in Command Palette (Ctrl+Shift+P), or execute dnx . run in shell from the directory of your project.
SHIFT+CTRL+B should work
However sometimes an issue can happen in a locked down non-adminstrator evironment:
If you open an existing C# application from the folder you should have a .sln (solution file) etc..
Commonly you can get these message in VS Code
Downloading package 'OmniSharp (.NET 4.6 / x64)' (19343 KB) .................... Done!
Downloading package '.NET Core Debugger (Windows / x64)' (39827 KB) .................... Done!
Installing package 'OmniSharp (.NET 4.6 / x64)'
Installing package '.NET Core Debugger (Windows / x64)'
Finished
Failed to spawn 'dotnet --info' //this is a possible issue
To which then you will be asked to install .NET CLI tools
If impossible to get SDK installed with no admin privilege - then use other solution.
Install the extension "Code Runner". Check if you can compile your program with csc (ex.: csc hello.cs). The command csc is shipped with Mono. Then add this to your VS Code user settings:
"code-runner.executorMap": {
"csharp": "echo '# calling mono\n' && cd $dir && csc /nologo $fileName && mono $dir$fileNameWithoutExt.exe",
// "csharp": "echo '# calling dotnet run\n' && dotnet run"
}
Open your C# file and use the execution key of Code Runner.
Edit: also added dotnet run, so you can choose how you want to execute your program: with Mono, or with dotnet. If you choose dotnet, then first create the project (dotnet new console, dotnet restore).
To Run a C# Project in VS Code Terminal
Install CodeRunner Extension in your VS Code (Extension ID: formulahendry.code-runner)
Go to Settings and open settings.json
Type in code-runner.executorMap
Find "csharp": "scriptcs"
Replace it with this "csharp": "cd $dir && dotnet run $fileName"
Your project should Run in VS Code Terminal once you press the run button or ALT + Shift + N

Compiling mono-2.6 (or later) on Ubuntu?

I am having to building mono from sources, since the Ubuntu package from badgerports is outdated (does not support .Net 4.0)
This is what I have done so far (mostly following instructions here):
cloned mono git repository
switched to branch tagged 2.6 (git checkout mono-2-6)
installed minimal mono on my machine so mono and mcs are available on machine
run ./autogen.sh --prefix=/usr/local
run make
After a few modules compile correctly, I get this error:
make[4]: Entering directory `/home/oompah/work/dev/mono/mono/mini'
CC mini.lo
CC liveness.lo
liveness.c: In function ‘mono_liveness_handle_exception_clauses’:
liveness.c:137: error: ‘MonoCompile’ has no member named ‘header’
make[4]: *** [liveness.lo] Error 1
make[4]: Leaving directory `/home/oompah/work/dev/mono/mono/mini'
make[3]: *** [all] Error 2
I have looked at the offending code, and indeed a header member is being accessed ...
void
mono_liveness_handle_exception_clauses (MonoCompile *cfg)
{
MonoBasicBlock *bb;
GSList *visited = NULL;
MonoMethodHeader *header = cfg->header;
...
}
Has anyone managed to build mono-2.6 (or later) on Ubuntu?
I've used the scripts provided at integratedwebsystems successfully to compile a recent version of mono on my system and run .net 4.0 applications.
an improved version of the script can be found on firegrass' github account
Joe Shields is packaging Mono 2.10 and is patching everything to default to .NET 4.0 for Ubuntu, you might want to poke him on twitter #directhex.

Categories

Resources