MonoDevelop fails to generate define symbols in build script
Hello, I think I may have found a bug in MonoDevelop that fails to take the "Define Symbols" specification n the project's compiler settings to produce /define in the csc's build script.
I have described the 2 ways to produce this bug in Linux Mint 18.3 using Flatpak MonoDevelop (ver 7.3.3. Build 5) and Normal MonoDevelop (ver 7.5 Build 1255) to make sure the bug is not an environmental issues due to incomplete installation of MonoDevelop. They both produce the same behaviour and hence I believe it is a MonoDevelop issue. Here are the ways I can reproduce the problem.
Method 1
This method requires one to have a Gtk#2 C# project (let's called it HelloWorld as it does not depend on any code other than a generated Gtk#2 project) that has the following characteristic:
-
The <PropertyGroup> containing a Condition like this: <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> and <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
-
Make sure the project has
that is not empty. The Debug target has the DEBUG defined at a minimum.
Step1 - Use the MonoDevelop to create a blank solution Step2 - Add the HelloWorld project to the solution. Step3 - Examine the HelloWorld's compiler setting to make sure the Platform is still "Any CPU" and the "Platform Target" is whatever set in the .csproj file for that target type and that there is a Defined Symbol. Step4 - clean the project and build it. Step5 - When finished, click on the Error Pad > Build Output and you can then study the csc commands. You will notice that the /define:DEBUG for a Debug target (or your define symbol) is not there. You can insert Debug.WriteLine() or #if DEBUG in your project and it will be commented out at run time confirming that the symbol DEBUG has not been defined.
Incidentally the IDE editor correctly picked up the definition of DEBUG (or whatever symbol you have defined in the compiler settings and applied the correct coloring to the code.
Method 2
This method can be produced all using code generated from the MonoDevelop.
Step1 - Create a blank solution
Step2 - Create a new Gtk#2 project (my HelloWorld) into the solution
By default, the debug target has DEBUG defined as set in the compiler settings. Hence building this project will produce a build script for csc containing the /define:DEBUG. You can confirm this via the Error Pad > Build Output.
Step3 - Remove (but do not physically delete the project) the HelloWorld project from the solution.
Step4 - Close the solution.
Stept5 - Edit the HelloWorld.csproj to make sure the
It seems if the project has "AnyCPU" as the platform, MonoDevelop fails to generate the /define:. You can change that to anything other than AnyCPU and MonoDevelop will behave normally.
Can someone confirm the above methods and steps are reproducible? Is there any explanation for this bizarre behaviour?
Thanks.
Johny
VS bug #650912
Hello,
Additional comment on this bug.
It appears the MonoDevelop IDE cannot handle GTK#2 project with the platform set to AnyCPU. Including project it generates. Below are the steps to replicate the bug.
Here is another way to demonstrate this bug. Step 1 - Generate a blank solution Step 2 - Generate a .Net Library project. In the .csproj file you can see the Platform in the Condition attribute is set to "AnyCPU". Building this Debug target of this project will produce a build script containing the /define:DEBUG
Step 3 - Generate a Gtk#2 project into the same solution calling HelloWorld. In the MainWindow.cs file, include the following lines after the Build() as such: `#if DEBUG
this.Title = "DEBUG";
#else
this.Title = "NOT DEBUG";
#endif ` Step 4 - Build the debug version of HelloWorld and have a look at the build script in the build output and you can see there is no /define:DEBUG.
Also notice the IDE correctly color the code for MainWindow.cs recognizing the definition of DEBUG.
Now run the HelloWorld and you can see the "NOT DEBUG" is displayed in the caption of the window indicating the absence of the definition at compile time.
To fix this edit the .csproj file and change it to x86 or x64 and all is then well.
Clearly there is a bug in MonoDevelop.
Johny
Hello, This problem is more bizarre as demonstrated by the following simple scenario all using the MonoDevelop functions:
- If you create a blank solution, then add a .Net library to the solution and followed by adding a Gtk#2 project (HelloWorld) to it. Building the debug version of HelloWorld project will show that the IDE does not emit the /define:DEBUG.
Examination of HelloWorld.csproj shows the platform is set to AnyCPU (as generated by MonoDevelop).
- Reversing the order of generation and adding project into a new solution - Add Gtks#2 project (HelloWorld) and the library - and building the debug version of HelloWorld shows the IDE emits the /define:DEBUG now to CSC. Strange!
In both scenario, HelloWorld does not have any reference to the .Net library.
This is because the platform for HelloWorld.csproj is now set to x86 rather than AnyCPU.
It begs the questions why:
- the order of including project seemingly influenced by what is in the solution controls the emission of specification for only GTK#2 project.
- Why a platform controls the emission of options to the compiler?
- What controls what platform one could use during the generation of the project?
If one encounters the result of the first scenario, that is your Debug.?????? is like comment at runtime, edit the .csproj (first remove it from the solution) to change the platform to either x86 or x64, and then reload this back to the solution. You should find the emission of the /define: in the CSC command list.
BTW, this misbehaviour is not in MonoDevelop 5.10 if that helps.
Johny