SonarQube Scanner for MSBuild on macOS using mono - xamarin

I'm trying to use SonarQube Scanner for MSBuild on a Xamarin project on macOS using mono. As MSBuild 15.0 is now shipped with Xamarin, I figured this could actually work.
I can successfully run the scanner's "begin" using mono like so:
mono sonar-scanner-msbuild-2/SonarQube.Scanner.MSBuild.exe begin /k:"KEY"
The command creates the following files:
.sonarqube/conf/SonarQubeAnalysisConfig.xml
.sonarqube/conf/SonarQubeRoslyn-cs.ruleset
.sonarqube/conf/cs/SonarLint.xml
Before running MSBuild, I've added the following import to the csproj files of my solution:
<Import Project="/Users/someuser/.local/share/Microsoft/MSBuild/14.0/Microsoft.Common.targets/ImportBefore/SonarQube.Integration.ImportBefore.targets" />
I'm running MSBuild using:
msbuild /t:Rebuild
Now the build starts correctly but eventually terminates with two errors:
"/Users/someuser/Project/Project.sln" (Rebuild target) (1) ->
"/Users/someuser/Project/Project.UI.iOS/Project.UI.iOS.csproj" (Rebuild target) (2) ->
"/Users/someuser/Project/Project.Core/Project.Core.csproj" (default target) (3:3) ->
(CoreCompile target) ->
CSC : error CS2001: Source file `/additionalfile:/Users/someuser/Project/.sonarqube/conf/cs/SonarLint.xml' could not be found [/Users/someuser/Project/Project.Core/Project.Core.csproj]
CSC : error CS2001: Source file `/additionalfile:/Users/someuser/Project/.sonarqube/conf/Project.Core_AnyCPU_Debug_1267/ProjectOutFolderPath.txt' could not be found [/Users/someuser/Project/Project.Core/Project.Core.csproj]
Both files do exist in the filesystem, the first file was created in the scanner's begin invocation and the second file was created during the MSBuild execution.
Why would MSBuild not be able to find / access these two files? Is there anything that can be done about it?

After checking with the folks taking care of MSBuild, the solution has been provided in this Github issue thread:
To quote radical's comment from the Github issue:
You could try building with csc by passing /p:CscToolExe=csc.exe /p:CscToolPath=/Library/Frameworks/Mono.framework/Versions/4.8.0/lib/mono/msbuild/15.0/bin/Roslyn/ to msbuild
Unfortunately, even though MSBuild works with the above adjustments, SonarQube fails afterwards. I will follow up with the SonarQube people to see whether this can be worked around.

Related

Building Xamarin.Forms iOS project from command line with msbuild

I'm trying to build a Xamarin.Forms iOS project via command line for CI/CD purposes directly on macOS:
msbuild C4S_MobileApp.iOS/C4S_MobileApp.iOS.csproj /restore /p:Platform=iPhone /p:ArchiveOnBuild=true /p:Configuration="Release" /p:BuildProjectReferences="false"
The problem is the shared app project which I avoid rebuilding with /p:BuildProjectReferences="false" and whose .dll can't be found:
CSC : error CS0006: Metadata file '/Users/c4s/Projects/c4s_refactored/c4s-refactored-mobile-app/C4S_MobileApp/bin/iPhone/Release/netstandard2.1/C4S.MobileApp.dll' could not be found [/Users/c4s/Projects/c4s_refactored/c4s-refactored-mobile-app/C4S_MobileApp.iOS/C4S_MobileApp.iOS.csproj]
MSBuild assumes the .dll in C4S_MobileApp/bin/iPhone/Release/netstandard2.1/ but it's in C4S_MobileApp/bin/Release/netstandard2.1. An ugly solution would be to copy the C4S.MobileApp.dll to that location. Building without /p:BuildProjectReferences="false" works because msbuild then creates C4S_MobileApp/bin/iPhone/Release/netstandard2.1/C4S.MobileApp.dll
I added the parameter /p:AssemblySearchPaths="C4S_MobileApp/bin/Release/netstandard2.1" to msbuild command and also added <AssemblySearchPaths>C4S_MobileApp/bin/Release/netstandard2.1;$(AssemblySearchPaths)</AssemblySearchPaths> to the C4S_MobileApp.iOS.csproj file under Release|iPhone configuration but it seems to be ignored by msbuild.
Folder structure:
c4s-refactored-mobile-app/
-> C4S_MobileApp/
-> C4S_MobileApp.iOS/
Thanks for your help and suggestions.
Unfortunately it's a bug in Xamarin.iOS: https://github.com/xamarin/xamarin-macios/issues/10308

Build specific Visual studio project under project solution using Msbuild and devenv

I have Visual studio project solution which has multiple .csproj. Each .csproj has some reference libraries.The project settings are made in such a way the reference libraries are built first and then .csproj is built. This works as expected when i run it in visual studio IDE. But when i try to execute using msbuild i'm getting an error saying target doesn't exist. Gone through many posts related to this issue ,tried possible things.But didn't built.Looks like i might be doing something silly or missing something in the settings.
Also tried using devenv from commandline. With this option i dont see any error but at same time the project doesnt build.I dont see any message after execution of command.Im using visual studio 2015
Here is my project structure
Poject.sln
ProjectA
porjectB
projectC
Libraries
libA
libB
msbuild "project.sln" target:"D:\Projects\Source\Demo\ProjectA\ProjectA.csproj" /t:build
"/p:Configuration=Debug" "/p:platform=x86"
I see the below error
"D:\project.sln" (D:\Projects\Source\Demo\ProjectA\;build target) (1) ->
D:\project.sln.metaproj : error MSB4057: The target "D:\Projects\Source\Demo\ProjectA" does not exist in the project. [D:\project.sln]
Here is the command used using devenv
devenv.exe "project.sln" /build Debug /project `"D:\Projects\source\Demo\Applications\ProjectA\ProjectA.csproj" /projectconfig Debug
After executing the above its doesnt build and i dont see any error too.
error MSB4057: The target "D:\Projects\Source\Demo\ProjectA" does not
exist in the project.
The error indicates your path in command is not valid and project.sln can't recognize the path. So you actually meet one path-related issue. And you should pass the ProjectA to the targets argument instead of ProjectA.csproj! More details see tip3 in For MSBuild.
For MSBuild:
1.If you're only trying to build ProjectA and its reference libraries.
Navigate(cd) to path where ProjectA.csproj exists, and then use command msbuild ProjectA.csproj /t:build /p:Configuration=Debug /p:platform=x86
Also you can directly use command msbuild AbsolutePath\ProjectA.csproj /t:build /p:Configuration=Debug /p:platform=x86. It's not necessary to use " to cover the path and arguments.
(ProjectA.csproj file should have definitions about the reference to those two library projects, so msbuild ProjectA.csproj will build those two projects first. You don't need to specify the xx.sln in your command.)
2.If you're trying to build whole solution(all the projects):
msbuild project.sln /t:build /p:Configuration=xxx /p:platform=xxx
Navigate to solution folder when you run above command, or use absolutepath\project.sln with that command.
3.When you want to build specific projects(more than one) in solution:
Check How to: Build Specific Targets in Solutions By Using MSBuild.exe. Since you're only build ProjectA, you don't need to use this format. For example: Only when you need to build both ProjectA and ProjectB, but not build ProjectC... You can use command like:
msbuild xxx.sln /t:NotInSlnfolder:Build;NewFolder\InSolutionFolder:Build
Pay attention to the path when you use this format. Whether your project is in solution folder can affect the build result a lot ! And, the direct cause of your issue, this command's targets argument needs one ProjectName as input instead of ProjectName.csproj.
For Devenv command:
1.I always use VS2017 and VS2019,so I'm not certainly sure if VS2015's devenv related command has big difference from VS2017's or VS2019's. But according to details from this VS2017 document:
Commands that begin with devenv are handled by the devenv.com utility, which delivers output through standard system streams, such as stdout and stderr.
Alternatively, commands that begin with devenv.exe can use the same switches, but the devenv.com utility is bypassed. Using devenv.exe directly prevents output from appearing on the console.
I think that's why you don't see any message after execution of command. You should use devenv.com command to see the output in console. And it's by design that devenv.exe will prevents output from appearing on the console.
2.The following command builds the project CSharpWinApp, using the Debug project build configuration within MySolution.
devenv "%USERPROFILE%\source\repos\MySolution.sln" /build Debug /project "CSharpWinApp\CSharpWinApp.csproj" /projectconfig Debug
More details about devenv reference please check this document.
In addition:
1.Looks like you have one strange project structure. I checked your error message above and it seems your several projects(xx.csproj) are not under Solution(xx.sln) folder. Just a suggestion, the normal folder structure for VS2015 is always:
Solution folder
xx.sln
ProjectA folder
ProjectA.csproj
ProjectB folder
ProjectB.csproj
2.For most of the projects, build using msbuild is more powerful and convenient than build using devenv. So if you don't have special reason, I recommend using Msbuild, the build engine of VS.
Hope all above helps to resolve your issue and puzzle. Let me know if your issue persists:)
File "/Users/morel893/Desktop/env/lib/python3.7/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: relation "projects_project" does not exist
LINE 1: ...ct"."technology", "projects_project"."image" FROM "projects_...

VS2017 MSB4057 The target "CreateManifestResourceNames" does not exist in the project

When VS2017 was used to create a stateful solution, producing the standard boilerplate code, the resulting two projects have two different MSBuild versions.
The application uses MSBuild version 1.5.0.
The service uses MSBuild version 1.6.0 (the current "latest").
If I run the solution this way, it runs fine on my local Service Fabric cluster.
But when after I use NuGet to update the application's MSBuild to 1.6.0 (so both application and server projects use the same), the following errors occur.
Severity Code Description Project File Line Suppression State
Error The OutputPath property is not set for project 'gt_strd5.sfproj'. Please check to make sure that you have specified a valid combination of Configuration and Platform for this project. Configuration='Debug' P follow a project-to-project reference to this project, this project has belatform='x64'. This error may also appear if some other project is trying toen unloaded or is not included in the solution, and the referencing project does not build using the same or an equivalent Configuration or Platform. gt_strd5 C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets 737
Severity Code Description Project File Line Suppression State
Error MSB4057 The target "CreateManifestResourceNames" does not exist in the project. gt_strd5 C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets 2630
I found that after the change, some references in the application's project file continued to reference MSBuild 1.5.0. In my case, the gt_strd5.sfproj file contained four references which needed to be updated from 1.5.0 to 1.6.0. See the snippets from the XML below.
Import Project="..\packages\Microsoft.VisualStudio.Azure.Fabric.**MSBuild.1.5.0**\build\Microsoft.VisualStudio.Azure.Fabric.Application.props" Condition="Exists('..\packages\Microsoft.VisualStudio.Azure.Fabric.**MSBuild.1.5.0**\build\Microsoft.VisualStudio.Azure.Fabric.Application.props')"
.....
Import Project="..\packages\Microsoft.VisualStudio.Azure.Fabric.**MSBuild.1.5.0**\build\Microsoft.VisualStudio.Azure.Fabric.Application.targets" Condition="Exists('..\packages\Microsoft.VisualStudio.Azure.Fabric.**MSBuild.1.5.0**\build\Microsoft.VisualStudio.Azure.Fabric.Application.targets')"
To verify this, I went back a couple times and was able to reproduce both the issue and this solution.
Hope it saves someone else some time.
Best Regards
I was getting this error into PCF control.
Run Developer Command Prompt VS2017/ VS2019
a) Remove white space from your folder like Test%20-%20PCFs (source control generated name) should be TestPCFs
b) Go to pcf project folder from cmd line & run msbuild /t:restore
b) Go to cds project folder from cmd line & run msbuild /t:restore
c) On cds project folder, run msbuild
d) For release deployment run msbuild /p:configuration=Release
For other types of projects
a) Remove white space from your folder name
b) run msbuild /t:restore
c) run msbuild

MSBuild 2015 fails packaging web app from VS2010

I have a build server that until recently had up to .Net 4.5.1 and VS2010/VS2012 installed. I ran MSBuild to build and package web apps as follows:
"C:\Program Files (x86)\MSBuild\12.0\Bin\MSBuild.exe" Hartford.Pace.sln /nologo /v:n /p:Configuration=Release /p:DeployOnBuild=True /p:CreatePackageOnPublish=True /p:AutoParameterizationWebConfigConnectionStrings=False /p:EnableNuGetPackageRestore=True
I recently updated the build server to include Frameworks through 4.6.1 and VS2013/VS2015. Everything was installed in sequence. I updated the build command to:
"C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe" Hartford.Pace.sln /nologo /v:n /p:Configuration=Release /p:DeployOnBuild=True /p:CreatePackageOnPublish=True /p:AutoParameterizationWebConfigConnectionStrings=False /p:EnableNuGetPackageRestore=True /p:VisualStudioVersion=10.0
And now I'm getting the following error only for VS2010 web apps:
"d:\a5\bi_hartsource_pace\Microsoft_Build_Web_App\trunk\Hartford.Pace.sln" (default target) (1) ->
"d:\a5\bi_hartsource_pace\Microsoft_Build_Web_App\trunk\Hartford.Pace.Services\Hartford.Pace.Services.csproj" (default target) (2) ->
(PackageUsingManifest target) ->
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets(3009,5): error : Web deployment task failed. (Unknown ProviderOption:DefiningProjectFullPath. Known ProviderOptions are:.) [d:\a5\bi_hartsource_pace\Microsoft_Build_Web_App\trunk\Hartford.Pace.Services\Hartford.Pace.Services.csproj]
Which points to a problem with the packaging target files. I checked them and none of them were changed by the update.
Does anyone know of side-by-side issues with VS2010 and VS2015? I'd like to upgrade the VS2010 Solutions but it's not my code and I need to build existing apps without modification.
Is this the best method for packaging an app without having the developers create publishing profiles or running anything at their end? This is supposed to be a fully automated build and deploy process. It has been working for three years with no issues but I'm open to suggestions that I can implement entirely on my build server without involving changing files in the source code (including csproj or other controlling files).
Add /p:VisualStudioVersion=10.0

What is the default location for MSBuild logs?

I am using Visual Studio Express 2012. Where is the location of the log file? I have searched in the folder where my solution and projects are stored, but cannot find any .log file.
This is the configuration for logging:
Log file from Visual Studio is only supported for C++ projects. You just have to work with the output window for others.
See this similar thread: VS2010: minimal build log in output and detailed log in log file
And in case you happen to do this for a C++ project, the file is at:
... build log in the intermediate files directory
... The path and name of the build log is represented by the MSBuild macro
expression, $(IntDir)\$(MSBuildProjectName).log.
Use build output instead of logging to file. Instead of copy/paste, simply click somewhere in the output and press CTRL + S to save. Visual Studio will prompt you for a location (tested with Visual Studio 2017, but I'm assuming this works in earlier versions too).
The msdn documentation is pretty clear about this (And you ain't gonna like it!):
https://msdn.microsoft.com/en-us/library/jj651643.aspx
Where it says:
To create a build log file for a managed-code project On the menu bar,
choose Build, Build Solution.
In the Output window, highlight the
information from the build, and then copy it to the Clipboard.
Open a
text editor, such as Notepad, paste the information into the file, and
then save it.
While it's true that VS doesn't allow this directly, it is still possible to build with MSBuild "inside" VS2015 and get both the build window output and the log file, as follows: (Arguably this is a bit of a hack.)
In your VS Managed solution, add a new project (Let's call it 'Make').
a. The project type you want is Visual C++/NMake project.
Define the MSBuild commands you need on the command line (see below).
Change the solution configuration to build the NMake project instead of the normal managed projects.
This will create a project that has Build, Rebuild, and Clean command lines where you can execute MSBuild directly. For example:
Rebuild: MSBuild.exe /ds /v:diag /property:Configuration=Debug ..\BuildTest\BuildTest.csproj /t:Clean,Build
Build: MSBuild.exe /ds /v:diag /property:Configuration=Debug ..\BuildTest\BuildTest.csproj /t:Build
Clean: MSBuild.exe /ds /v:diag /property:Configuration=Debug ..\BuildTest\BuildTest.csproj /t:Clean
You can also specify multiple MSBuild.EXE command lines in order to build multiple projects. For the usual build-the-entire-solution outcome you can target only the final end assemblies and let the dependency graph generate the individual targets.
This will produce a .log file, where NAME is the name of the NMake project you used. In the example above, the log would be make.log.
A working example is available on GitHub:
https://github.com/bitblitz/VS_MsbuildExample
(Tested with VS2015)
Note that building individual projects directly will still build with the normal VS behavior, but you can build the full solution inside VS and get the build logs.

Resources