Unable to use xbuild to build solution (Mono) - c#

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

Related

just installed dotnet, dot new console and dotnet --version are working but dotnet run gives error. I'm trying to edit unity scripts from vscode

I'm following this guide to connect unity with VScode.
This guide led me to here
After installing dotnet i run the following commands according to guide and got a long list of errors.
PS C:\Users\SMME> dotnet new console --force
Processing post-creation actions...
Running 'dotnet restore' on C:\Users\SMME\SMME.csproj...
Determining projects to restore...
Restored C:\Users\SMME\SMME.csproj (in 92 ms).
Restore succeeded.
PS C:\Users\SMME> dotnet --version
6.0.404
PS C:\Users\SMME> dotnet run
C:\Users\SMME\AppData\Local\Programs\Python\Python311\tcl\tix8.4.3\pref\Blue.cs(1,1): error CS1024: Preprocessor directive expected [C:\Users\SMM
E\SMME.csproj]
C:\Users\SMME\AppData\Local\Programs\Python\Python311\tcl\tix8.4.3\pref\Bisque.cs(1,1): error CS1024: Preprocessor directive expected [C:\Users\S
MME\SMME.csproj]
C:\Users\SMME\AppData\Local\Programs\Python\Python311\tcl\tix8.4.3\pref\Blue.cs(2,1): error CS1024: Preprocessor directive expected [C:\Users\SMM
E\SMME.csproj]
C:\Users\SMME\AppData\Local\Programs\Python\Python311\tcl\tix8.4.3\pref\Bisque.cs(2,1): error CS1024: Preprocessor directive expected [C:\Users\S
MME\SMME.csproj]
C:\Users\SMME\AppData\Local\Programs\Python\Python311\tcl\tix8.4.3\pref\Bisque.cs(3,1): error CS1024: Preprocessor directive expected [C:\Users\S
MME\SMME.csproj]
C:\Users\SMME\AppData\Local\Programs\Python\Python311\tcl\tix8.4.3\pref\Blue.cs(3,1): error CS1024: Preprocessor directive expected [C:\Users\SMM
E\SMME.csproj]
Many line of similar errors
C:\Users\SMME\AppData\Local\Programs\Python\Python311\tcl\tix8.4.3\pref\WmDefault.cs(43,42): error CS7000: Unexpected use of an aliased name [C:\
Users\SMME\SMME.csproj]
C:\Users\SMME\AppData\Local\Programs\Python\Python311\tcl\tix8.4.3\pref\WmDefault.cs(43,55): error CS1002: ; expected [C:\Users\SMME\SMME.csproj]
The build failed. Fix the build errors and run again.
Contents of SMME.csproj are
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
Please help if you have any idea why my original code was not working or this new dotnet installation is not working.
Actually I was using unity and scripting with vscode.
I got stuck here following the pathway from unity learn.
Create a new DetectCollisions.cs script, add it to each animal prefab, then open it
Before the final } add OnTriggerEnter function using autocomplete
In OnTriggerEnter, put Destroy(gameObject);, then test
In OnTriggerEnter, put Destroy(other.gameObject);
My vscode was not autocompleting OnTriggerEnter function, so i manually typed it but didn't work too. I searched for a solution in unity forums, reddit and stack exchange, some suggested to change unity editor settings while other VScode settings but nothing worked.
After trying everyth i deleted VScode completely with extensions and all .NET sdk's that i had installed.
Now i'm trying to install everyth from scratch but I got stuck at very first step.

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\".

"dotnet build" command fails with error MSB6006: "csc.exe" exited with code 1

I'm trying to get a Xamarin Forms solution to build from the command line as part of a build script using the command dotnet build <solution.sln>. Most of the projects in the solution build; however, two projects fail with this error message: error MSB6006: "csc.exe" exited with code 1.(on Ubuntu) and error MSB6006: "csc.exe" exited with code 8. (on Mac).
I have running Ubuntu 18.04 (using Windows subsystem for Linux) and MacOS 10.13.6 on separate machines.
I have also tried to run dotnet build <solution.sln> from the windows command line which prints out this error message instead:
error MSB4062: The "XamarinLive.Build.XamarinLiveTask" task could not be loaded from the assembly C:\Users\Jason.nuget\packages\livexaml\2.1.22\build\XamarinLive.Build.dll. Could not load file or assembly 'Microsoft.Build.Utilities.v4.0, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified. Confirm that the declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask.
However, the solution works and builds fine from within VS2017 (Version 15.9.7). I've tried scouring the binary log that is generated but I can't make much sense of it and there doesn't seem to be any obvious errors (on Ubuntu & Mac). Could the windows error message be related in some way?
The projects that are failing target netstandard 2.0 (The same as the projects that do build). The version returned by dotnet --version on all 3 environments is 2.1.504.
Any help would be greatly appreciated.
You need to use msbuild.exe instead of dotnet
build
for this situation.
msbuild.exe runs on full framework while dotnet buildruns on .NET Core, and most of the build tasks don't support that.
When you build them in VS,it actually calls the msbuild.exe to build the solution.So you can build it well by developer command prompt since it also calls the msbuild.exe.
For vs2017, you can find it in C:\Program Files (x86)\Microsoft Visual Studio\2017\Edition\MSBuild\15.0\Bin.
More details see Martin's answer from this similar issue. Thanks to his detailed description!

VSTS - Uno with Xamarin iOS Build error for C# 7.1 feature while LangVersion is properly set

When building on vsts (windows hosted machine) I have the following error:
Operator '==' cannot be applied to operand 'default'
However, in my project I have:
<PropertyGroup>
<LangVersion>7.1</LangVersion>
</PropertyGroup>
Moreover, on my machine it does build (in Debug AND Release modes).
UPDATE
The error first appeared while I had the following:
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<LangVersion>7.1</LangVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<LangVersion>7.1</LangVersion>
</PropertyGroup>
Note that this is a library and that I do multi-targeting (netstandard2.0;xamarinios10) but I don't see why it should matter.
UPDATE2
I tried
<PropertyGroup>
<LangVersion>7.1</LangVersion>
</PropertyGroup>
Looking in the logs I see:
/reference:/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/Facades/System.Xml.Xsl.Primitives.dll /debug- /debug:portable /filealign:512 /nologo /optimize+ /out:obj/Release/xamarinios10/MyApp.ViewModels.dll /target:library /warnaserror- /utf8output /deterministic+ /langversion:latest /analyzer:/Users/vsts/.nuget/packages/uno.ui/1.31.0-dev.8/analyzers/Uno.Analyzers.dll MyViewModelA.cs MyViewModelB.cs... Parameter.cs ReactiveGroup.cs "/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/Xamarin.iOS,Version=v1.0.AssemblyAttributes.cs" obj/Release/xamarinios10/MyApp.ViewModels.AssemblyInfo.cs /warnaserror+:NU1605
2018-06-27T20:11:28.5184750Z MyViewModelA.cs(105,89): error CS8310: Operator '==' cannot be applied to operand 'default' [/Users/vsts/agent/2.134.2/work/1/s/MyApp.ViewModels/MyApp.ViewModels.csproj]
So I think it may not be a build error but some kind of Uno Analyser error.
Side note: it is strange that the log mentions uno.ui/1.31.0-dev.8 as I had upgraded the package (see below). As if there were some caching involved I don't know how.
<PackageReference Include="Uno.UI" Version="1.31.0-dev.79" />
UPDATE3
I can't copy the full log here but here the csc command for the project that fails to build:
/Library/Frameworks/Mono.framework/Versions/5.8.1/lib/mono/4.5/csc.exe /noconfig /unsafe- /checked- /nowarn:1701,1702,1705 /langversion:latest /nostdlib+ /errorreport:prompt /warn:4 /define:__IOS__;__MOBILE__;__UNIFIED__;TRACE;RELEASE;XAMARINIOS1_0
UPDATE4
Thanks to #JeromeLaban, who provided me with that link about Mono 5.8.0, as it shows that version of mono is compatible with C# 7.0 only.
However, the specs of the MacOs queue say that there is Mono 5.10 installed and that version is up to C# 7.2.
So the next question (and I wrote a dedicated question) is how to specify the mono version to build with.
The xamarinios vsts task that I run on the hosted vsts MacOs queue runs mono 5.8.0 (even though mono 5.10.0 is installed on that queue as per specs). And version 5.8.0 is compatible up to C# 7.0 so it cannot run C# 7.1 code.

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

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.

Categories

Resources