Mono - Building/running Microsoft Compact Framework applications under Mono? - c#

I'm trying to build a .NET project on Mono.
efulmer:[~/projects/MyApp]$ msbuild MyApp.csproj
Microsoft (R) Build Engine version 15.3.0.0 ( Mon Aug 14 21:03:24 UTC 2017) for Mono
Copyright (C) Microsoft Corporation. All rights reserved.
Build started 10/11/2017 3:46:23 PM.
Project "/home/efulmer/projects/MyApp/MyApp.csproj" on node 1 (default targets).
/home/efulmer/projects/MyApp/MyApp.csproj(161,3): error MSB4019: The imported project "/usr/lib/mono/msbuild/15.0/bin/Microsoft.CompactFramework.CSharp.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.
Done Building Project "/home/efulmer/projects/MyApp/MyApp.csproj" (default targets) -- FAILED.
Build FAILED.
"/home/efulmer/projects/MyApp/MyApp.csproj" (default target) (1) ->
/home/efulmer/projects/MyApp/MyApp.csproj(161,3): error MSB4019: The imported project "/usr/lib/mono/msbuild/15.0/bin/Microsoft.CompactFramework.CSharp.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:00.14
The line in question is <Import Project="$(MSBuildBinPath)/Microsoft.CompactFramework.CSharp.targets" />
The underlying problem is fairly obvious to me after some searching (missing .NET Compact Framework) but I'm not sure how to solve it, as I installed mono-complete. But I don't know how to solve it. Help appreciated!

You may have a problem with case sensitivity. I had a similar problem with a program not finding Microsoft.CSHARP.Targets
It turns out that MSBuild provides a file called Microsoft.CSharp.targets
I created a symlink from Microsoft.CSHARP.Targets to Microsoft.CSharp.targets and that worked around the problem.

Related

How do I solve error MSB4041 (VS2017, C#, MSBuild, SpecFlow.Tools.MsBuild.Generation, SpecRun)?

I have an automation test suite, attempting to use SpecRun to run tests in parallel. It appears that rather than being able to run tests in Test Explorer, I need to instead run them using the provided "runtests.cmd" file...
#pushd %~dp0
#where /q msbuild
#IF ERRORLEVEL 1 (
echo "MSBuild is not in your PATH. Please use a developer command prompt!"
goto :end
) ELSE (
MSBuild.exe "C:\Users\me\source\repos\OurAutomation\src\OurAutomation.csproj"
)
#if ERRORLEVEL 1 goto end
#cd ..\packages\SpecRun.Runner.*\tools\net45
#set profile=%1
#if "%profile%" == "" set profile=Default
#if exist "%~dp0\bin\Debug\%profile%.srprofile" (
SpecRun.exe run "%profile%.srprofile" --baseFolder "%~dp0\bin\Debug" --log "specrun.log" %2 %3 %4 %5
) else (
SpecRun.exe run --baseFolder "%~dp0\bin\Debug" --log "specrun.log" %2 %3 %4 %5
)
:end
#popd
pause
...the pause statement is something I added in to keep the console open to see the errors.
The errors are:
Microsoft (R) Build Engine version 4.7.3056.0
[Microsoft .NET Framework, version 4.0.30319.42000]
Copyright (C) Microsoft Corporation. All rights reserved.
Build started 08/07/2019 11:15:06.
Project "C:\Users\me\source\repos\OurAutomation\src\OurAutomation.csproj" on node 1 (defau
lt targets).
C:\Users\me\source\repos\OurAutomation\src\packages\SpecFlow.Tools.MsBuild.Generation.3.0.220\build\Sp
ecFlow.Tools.MsBuild.Generation.props(1,1): error MSB4041: The default XML namespace of the project must be the MSBuild
XML namespace. If the project is authored in the MSBuild 2003 format, please add xmlns="http://schemas.microsoft.com/d
eveloper/msbuild/2003" to the <Project> element. If the project has been authored in the old 1.0 or 1.2 format, please
convert it to MSBuild 2003 format. [C:\Users\me\source\repos\OurAutomation\src\OurAutomati
on.csproj]
Done Building Project "C:\Users\me\source\repos\OurAutomation\src\OurAutomation.csproj" (d
efault targets) -- FAILED.
Build FAILED.
"C:\Users\me\source\repos\OurAutomation\src\OurAutomation.csproj" (default target) (1) ->
C:\Users\me\source\repos\OurAutomation\src\packages\SpecFlow.Tools.MsBuild.Generation.3.0.220\build\
SpecFlow.Tools.MsBuild.Generation.props(1,1): error MSB4041: The default XML namespace of the project must be the MSBui
ld XML namespace. If the project is authored in the MSBuild 2003 format, please add xmlns="http://schemas.microsoft.com
/developer/msbuild/2003" to the <Project> element. If the project has been authored in the old 1.0 or 1.2 format, pleas
e convert it to MSBuild 2003 format. [C:\Users\me\source\repos\OurAutomation\src\OurAutoma
tion.csproj]
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:00.02
I've set the system environment variable PATH to look for MSBuild.exe in C:\Windows\Microsoft.NET\Framework\v4.0.30319 (this is the latest version I have).
I tried to do as the error suggested, and found that both OurAutomation.csproj and OurAutomation.csproj.user files already have:
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
So that's the simple fix out of the way - no fix at all, because the Project tag already has the required attribute and value!
I've been on several websites looking for an alternative solution. Others are saying that they had this problem when upgrading from VS2015 to 2017 (they changed from using project.json to *.csproj). However I have not upgraded. I created my project in VS2017. Target framework: .NET Framework 4.7.2, Output type: Class Library.
Not sure if SpecFlow.Tools.MsBuild.Generation is introducing a conflict here, but I do need it.
Please do you know how I would go about fixing this? Running out of ideas.
Thank you.
Pavel Anikhouski's answer was the solution, thank you!
"Starting from VisualStudio 2015 MSBuild is provided as part of IDE (or build tools), you should use this version, e.g. c:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\".

Unable to use xbuild to build solution (Mono)

When trying to use xbuild to build my solution through Mono on Mac and Linux (haven't tested under Windows yet), I get this strange error that I've been unable to find anywhere else.
Errors:
/Users/macbook/git/DiscordSharp/DiscordSharp.sln (default targets) ->
(Build target) ->
/Users/macbook/git/DiscordSharp/DiscordSharp/DiscordSharp.csproj (default targets) ->
/Library/Frameworks/Mono.framework/Versions/4.2.2/lib/mono/4.5/Microsoft.CSharp.targets (CoreCompile target) ->
/Library/Frameworks/Mono.framework/Versions/4.2.2/lib/mono/4.5/Microsoft.CSharp.targets: error : Tool executable '/MSBuild/14.0/Bin/mcs.exe' could not be found
1 Warning(s)
1 Error(s)
Time Elapsed 00:00:02.0472770
MacBooks-MacBook:DiscordSharp macbook$
Interestingly enough, I am able to open the solution in MonoDevelop and build it that way. The projects in the solution target Mono / .NET Framework 4.5. I'm running Mono 4.2 SR1 (4.2.2.30).
What could be causing this issue and in what way could I fix it? This problem prevented me from using TravisCI with this project and I have yet to find a fix for it.
The .csproj file is only defining a non-Unix CscToolPath for a Platform conditional (OS should be used...), not sure what the requirement is for v14 for Windows(?), so as a test:
vi DiscordSharp/DiscordSharp.csproj
Remove:
<PropertyGroup Condition="'$(Platform)' != 'Unix'">
<CscToolPath>$(MSBuildProgramFiles32)\MSBuild\14.0\Bin</CscToolPath>
</PropertyGroup>
Rebuild project and it should work fine:
nuget restore
xbuild DiscordSharp.sln
If v14 MSbuild is required for Windows, you can use the following:
<PropertyGroup Condition="'$(OS)' != 'Unix'">
<CscToolPath>$(MSBuildProgramFiles32)\MSBuild\14.0\Bin</CscToolPath>
</PropertyGroup>
http://www.mono-project.com/archived/porting_msbuild_projects_to_xbuild/
Then the following should run fine with no errors:
xbuild /target:clean
xbuild /target:build

Some confusions about Command Line Compiler and MSBuild

C# CSC.exe
If we give it a C# file, a .CS , is it able to compile it and say for example a ";" is missing at line 12 of your code? In a form that later in my program - which is Java RCP app, I can show those compile errors in a Spreadsheet
How about MSBuild? Is that able to show compile errors same as my previous example?
Think of MSBuild as a glorified make or something more like ANT - it is a language for describing compilation/build tasks. When you use MSBuild for building your c# program, you are actually using csc.exe for the compilation part.
Say this is your code (program.cs):
namespace MyCustomBuild
{
class Program
{
static void Main(string[] args)
{
System.Console.WriteLine("Hello World")
}
}
}
You can call csc program.cs and receive the following output
Microsoft (R) Visual C# 2010 Compiler version 4.0.30319.1
Copyright (C) Microsoft Corporation. All rights reserved.
program.cs(7,52): error CS1002: ; expected
Alternatively you can use msbuild to achieve the exact same result! Here is the content of build.msbuild
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="Default">
<Csc Sources="program.cs"/>
</Target>
</Project>
You can then call your msbuild file with varying levels of verbosity, as shown.
msbuild build.msbuild /verbosity:quiet and msbuild build.msbuild /verbosity:minimal
Microsoft (R) Build Engine Version 4.0.30319.1
[Microsoft .NET Framework, Version 4.0.30319.269]
Copyright (C) Microsoft Corporation 2007. All rights reserved.
program.cs(7,52): error CS1002: ; expected [<filePath>\build.msbuild]
msbuild build.msbuild /verbosity:normal:
Microsoft (R) Build Engine Version 4.0.30319.1
[Microsoft .NET Framework, Version 4.0.30319.269]
Copyright (C) Microsoft Corporation 2007. All rights reserved.
Build started 6/6/2012 12:13:00 PM.
Project "<filePath>\build.msbuild" on node 1 (default targets).
Default:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Csc.exe /out:program.exe program.cs
program.cs(7,52): error CS1002: ; expected [<filePath>\build.msbuild]
Done Building Project "<filePath>\build.msbuild" (default targets) -- FAILED.
Build FAILED.
"<filePath>\build.msbuild" (default target) (1) ->
(Default target) ->
program.cs(7,52): error CS1002: ; expected ["<filePath>\build.msbuild]
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:00.28
The remaining two verbosity levels are detailed and diagnostic and they present even more information if you want it. I'm not sure how much information you want for your spreadsheet, but hopefully one of these works for you.

Mono xbuild error CS1548 - key file has incorrect format

So I'm trying to get a VS2010 C# project to go cross-platform. First goal is build it in Mono 2.10.5 for Windows. I have not touched any code yet - I'm starting with xbuild's recent ability to build sln files. (Incidentally I use Jenkins to trigger builds, not that it matters as I get the same result at the command-line.)
I get "error CS1548: Error during assembly signing. The specified key file `AlphaBeta.pfx' has incorrect format". There's not much google juice on this error. Does anyone know what would cause this? Thanks in advance!
Full output below:
C:\Program Files\Jenkins\jobs\AlphaBeta\...\AlphaSolution>"C:\Program Files\Mono-2.10.5\bin\xbuild" AlphaSolution.sln
XBuild Engine Version 2.10.5.0
Mono, Version 2.10.5.0
Copyright (C) Marek Sieradzki 2005-2008, Novell 2008-2011.
Build started 9/20/2011 3:54:14 PM.
C:\Program Files\Jenkins\jobs\AlphaBeta\...\AlphaSolution\AlphaSolution.sln: warning : Ignoring vcproj 'ZBM'.
C:\Program Files\Jenkins\jobs\AlphaBeta\...\AlphaSolution\AlphaSolution.sln: warning : Don't know how to handle GlobalSection TestCaseManagementSettings, Ignoring.
C:\Program Files\Jenkins\jobs\AlphaBeta\...\AlphaSolution\AlphaSolution.sln: warning : Failed to find project d393406d-3397-4907-a536-2a4b77512bc6
Project "C:\Program Files\Jenkins\jobs\AlphaBeta\...\AlphaSolution\AlphaSolution.sln" (default target(s)):
Target ValidateSolutionConfiguration:
Building solution configuration "Debug|Mixed Platforms".
Target Build:
Project "C:\Program Files\Jenkins\jobs\AlphaBeta\...\AlphaSolution\AlphaCommon\AlphaCommon.csproj" (default target(s)):
Target PrepareForBuild:
Configuration: Debug Platform: AnyCPU
Target GenerateSatelliteAssemblies:
No input files were specified for target GenerateSatelliteAssemblies, skipping.
Target CoreCompile:
Tool C:\PROGRA~1\MONO-2~1.5\bin\dmcs.bat execution started with arguments: /noconfig /debug:full /debug+ /keyfile:AlphaBeta.pfx /optimize- /out:obj\Debug\AlphaCommon.dll AlphaCommon.cs Properties\AssemblyInfo.cs /target:library /define:"DEBUG;TRACE" /reference:C:\PROGRA~1\MONO-2~1.5\lib\mono\xbuild-frameworks\.NETFramework\v4.0\RedistList\..\..\..\..\4.0\System.dll /reference:C:\PROGRA~1\MONO-2~1.5\lib\mono\xbuild-frameworks\.NETFramework\v4.0\RedistList\..\..\..\..\4.0\System.Xml.Linq.dll /reference:C:\PROGRA~1\MONO-2~1.5\lib\mono\xbuild-frameworks\.NETFramework\v4.0\RedistList\..\..\..\..\4.0\System.Data.DataSetExtensions.dll /reference:C:\PROGRA~1\MONO-2~1.5\lib\mono\xbuild-frameworks\.NETFramework\v4.0\RedistList\..\..\..\..\4.0\Microsoft.CSharp.dll /reference:C:\PROGRA~1\MONO-2~1.5\lib\mono\xbuild-frameworks\.NETFramework\v4.0\RedistList\..\..\..\..\4.0\System.Data.dll /reference:C:\PROGRA~1\MONO-2~1.5\lib\mono\xbuild-frameworks\.NETFramework\v4.0\RedistList\..\..\..\..\4.0\System.Xml.dll /reference:C:\PROGRA~1\MONO-2~1.5\lib\mono\xbuild-frameworks\.NETFramework\v4.0\RedistList\..\..\..\..\4.0\System.Core.dll /warn:4
: error CS1548: Error during assembly signing. The specified key file `AlphaBeta.pfx' has incorrect format
Task "Csc" execution -- FAILED
Done building target "CoreCompile" in project "C:\Program Files\Jenkins\jobs\AlphaBeta\...\AlphaSolution\AlphaCommon\AlphaCommon.csproj".-- FAILED
Mono does not support using PKCS#12 (.pfx) files to store keys used for strongnaming assemblies. This is a known issue and tracked on Xamarin's bugzilla #725.
A workaround is to export your key into a .snk file and use this when building your project.
The answers here provide examples of how to generate an .snk from a .pfx.

Simple HelloWorld build script

I have a simple HelloWorld application that I'm trying to build using NAnt. However, even with the simplest of build files, I still cannot get it to work. Below is my HelloWorld.build file.
<?xml version="1.0"?>
<project name="Hello World" default="build">
<property name="nant.settings.currentframework" value="net-3.5"/>
<target name="build">
<echo>Hello</echo>
<exec program="${framework::get-framework-directory(framework::get-target-framework())}\msbuild.exe"
commandline="HelloWorld /t:Clean /p:Configuration=Debug /v:q" workingdir="." />
</target>
Here are the results.
C:\webdev\HelloWorld>c:\nant-0.86-beta1\bin\NAnt.exe build
NAnt 0.86 (Build 0.86.2898.0; beta1; 12/8/2007)
Copyright (C) 2001-2007 Gerry Shaw
http://nant.sourceforge.net
Buildfile: file:///C:/webdev/HelloWorld/HelloWorld.build
Target framework: Microsoft .NET Framework 2.0
Target(s) specified: build
[property] Target framework changed to "Microsoft .NET Framework 3.5".
BUILD FAILED
INTERNAL ERROR
System.NullReferenceException: Object reference not set to an instance of an object.
at NAnt.Core.FrameworkInfo.get_Version()
at NAnt.Core.Project.UpdateTargetFrameworkProperties()
at NAnt.Core.Tasks.PropertyTask.ExecuteTask()
at NAnt.Core.Task.Execute()
at NAnt.Core.Project.InitializeProjectDocument(XmlDocument doc)
at NAnt.Core.Project.Execute()
at NAnt.Core.Project.Run()
Please send bug report to nant-developers#lists.sourceforge.net.
Total time: 0 seconds.
Also, when I try to manually set the .NET framework to use, I get the following:
C:\webdev\HelloWorld>c:\nant-0.86-beta1\bin\NAnt.exe -t:net-3.5
NAnt 0.86 (Build 0.86.2898.0; beta1; 12/8/2007)
Copyright (C) 2001-2007 Gerry Shaw
http://nant.sourceforge.net
Microsoft .NET Framework 3.5 (net-3.5) is not installed, or not correctly configured.
Object reference not set to an instance of an object.
However, the config file does have an entry for .NET 3.5 .This is with NAnt-0.86-beta and Visual C# 2008 Express Edition. Am I completely off track? If so, does anyone perhaps have a template build file that can be reused?
Thank you.
Well I tried your build file on a very simple console application and aside from tweaking the command line arguments it all works just fine for me.
Have you tried to reinstall the .net framework 3.5 as it definately looks like thats missing (what happens if you try and execute msbuild from the cmd line with the exact path from the 3.5 framework directory ?)
<?xml version="1.0"?>
<project name="HelloWorld" default="build">
<property name="nant.settings.currentframework" value="net-3.5"/>
<target name="build">
<echo>Hello</echo>
<exec program="${framework::get-framework-directory(framework::get-target-framework())}\msbuild.exe" commandline="HelloWorld.sln /t:Clean /p:Configuration=Debug /v:q" workingdir="." />
</target>
</project>
the output for my project looks like this
NAnt 0.86 (Build 0.86.2898.0; beta1; 08/12/2007)
Copyright (C) 2001-2007 Gerry Shaw
http://nant.sourceforge.net
Buildfile: file:///C:/Documents and Settings/krystan/My Documents/Visual Studio
2008/Projects/HelloWorld/test.build
Target framework: Microsoft .NET Framework 3.5
Target(s) specified: build
build:
[echo] Hello
[exec] Microsoft (R) Build Engine Version 3.5.30729.1
[exec] [Microsoft .NET Framework, Version 2.0.50727.3082]
[exec] Copyright (C) Microsoft Corporation 2007. All rights reserved.
[exec]
BUILD SUCCEEDED
Total time: 0.2 seconds.
Some times this error is because the build server does not have the sdk installed.
Try installing the windows sdk. You can download it on the Microsoft Download Center
Additional steps may be needed to get nant to recognize the sdk, please refer to this Page Brook's Blog Post
There is a bug in Nant 0.86, see
http://sourceforge.net/tracker/index.php?func=detail&aid=1986551&group_id=31650&atid=402868
for more info.
You can download Nant nightly build (currently nant-0.86-nightly-2009-05-05) which has this bug fixed.

Categories

Resources