Xamarin xbuild: Warning when building .shproj-Files - xamarin

Given a Xamarin Studio solution containing a shared project, and an iOS project referencing the shared project. When building the solution with xbuild like this:
xbuild /p:Configuration=Release /p:Platform="iPhone" /target:Build GridVisibilityBug.sln
The build contains several warnings like the following:
/Users/work/.../GridVisibilityBug/GridVisibilityBug.shproj: warning : Could not find project file /Library/Frameworks/Mono.framework/External/xbuild/Microsoft/VisualStudio/v/CodeSharing/Microsoft.CodeSharing.Common.Default.props, to import. Ignoring.
/Users/work/.../GridVisibilityBug/GridVisibilityBug.shproj: warning : Could not find project file /Library/Frameworks/Mono.framework/External/xbuild/Microsoft/VisualStudio/v/CodeSharing/Microsoft.CodeSharing.Common.props, to import. Ignoring.
/Users/work/.../GridVisibilityBug/GridVisibilityBug.shproj: warning : Could not find project file /Library/Frameworks/Mono.framework/External/xbuild/Microsoft/VisualStudio/v/CodeSharing/Microsoft.CodeSharing.CSharp.targets, to import. Ignoring.
When building just the csproj, I do not get the warnings (just building the csproj is not desirable however, because the solution contains other projects):
xbuild /p:Configuration=Release /p:Platform="iPhone" /target:Build iOS/GridVisibilityBug.iOS.csproj
When building with the deprecated mdtool, I do not get the warnings either:
/Applications/Xamarin\ Studio.app/Contents/MacOS/mdtool -v build "--configuration:Release|iPhone" GridVisibilityBug.sln
How should I rate this warning? Is it harmless, or is there something serious missing? Can I fix the warning (the referenced files really are not located at the given location)?
I'm using older Xamarin version, due to the project being in a longer release period:
Xamarin Studio
Version 5.10.2 (build 56)
Installation UUID: 09335063-06f8-425b-8e56-2cdecfb3c10c
Runtime:
Mono 4.2.2 (explicit/996df3c)
GTK+ 2.24.23 (Raleigh theme)
Apple Developer Tools
Xcode 7.3.1 (10188.1)
Build 7D1014
Xamarin.iOS
Version: 9.4.1.25 (Business Edition)
Hash: 962a050
Branch: master
Build date: 2016-01-29 16:59:11-0500
Operating System
Mac OS X 10.11.6
Darwin Stephans-MacBook-Pro.local 15.6.0 Darwin Kernel Version 15.6.0
Mon Aug 29 20:21:34 PDT 2016
root:xnu-3248.60.11~1/RELEASE_X86_64 x86_64
Edit:
The initial example should now be more clear. The example project I used is the one attached to https://bugzilla.xamarin.com/show_bug.cgi?id=46501. It was created with the Xamarion Studio / Xamarin iOS versions mentioned above.
I've also been able to reproduce the problem on the system with newer Xamarin versions. Workflow: Create a new solution via File->New->Solution->Xamarin.Forms App, select shared project and iOS only. Then build the solution with the xbuild command mentioned above. Versions on this system: Xamarin Studio 6.1.1, Mono 4.6.1, Xamarin iOS 10.0.1.8, Mac OS X 10.11.6.
Edit 2:
The shproj xml indeed imports the files mentioned in the warning, and the files are not present on our systems. At least not in the expected location. The build itself works though. My main question is if these warnings can be ignored safely.

Related

dotnet build not finding Xamarin

When running dotnet build in my project, I have the following error:
/path/to/repo/Toolkit/My.Company.Toolkit.Platform.Android/My.Company.Toolkit.Platform.Android.csproj(91,3): error MSB4019: The imported project "/usr/local/share/dotnet/sdk/7.0.102/Xamarin/Android/Xamarin.Android.CSharp.targets" was not found. Confirm that the expression in the Import declaration "/usr/local/share/dotnet/sdk/7.0.102//Xamarin/Android/Xamarin.Android.CSharp.targets" is correct, and that the file exists on disk.
/path/to/repo/Toolkit/My.Company.Toolkit.Platform.iOS/My.Company.Toolkit.Platform.iOS.csproj(195,3): error MSB4019: The imported project "/usr/local/share/dotnet/sdk/7.0.102/Xamarin/iOS/Xamarin.iOS.CSharp.targets" was not found. Confirm that the expression in the Import declaration "/usr/local/share/dotnet/sdk/7.0.102//Xamarin/iOS/Xamarin.iOS.CSharp.targets" is correct, and that the file exists on disk.
I confirm that /usr/local/share/dotnet/sdk/7.0.102/Xamarin/iOS/Xamarin.iOS.CSharp.targets does not exist.
But I don't know how to install it there.
The reference to Xamarin is defined in the csproj like this <Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />.
When I build from Visual Studio I have no issues. And if I try to re-install Xamarin, it says it is already installed.
I am on MacOS.
[UPDATE]
I uninstalled everything (Visual Studio, SDKs/Runtime, dotnet, etc).
Installed just Visual Studio 2022 for Mac.
➜ ~ dotnet --info
.NET SDK:
Version: 7.0.102
Commit: 4bbdd14480
Runtime Environment:
OS Name: Mac OS X
OS Version: 13.1
OS Platform: Darwin
RID: osx.13-arm64
Base Path: /usr/local/share/dotnet/sdk/7.0.102/
Host:
Version: 7.0.2
Architecture: arm64
Commit: d037e070eb
.NET SDKs installed:
6.0.405 [/usr/local/share/dotnet/sdk]
7.0.102 [/usr/local/share/dotnet/sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 6.0.13 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.2 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.13 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.2 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Other architectures found:
None
Environment variables:
Not set
global.json file:
Not found
Learn more:
https://aka.ms/dotnet/info
Download .NET:
https://aka.ms/dotnet/download
Now if I try to build the project in the terminal I still have the same error. But if I try to build it from Visual Studio I have a different error.
I have this error in the build output
Target RazorGenerateComponentDeclaration:
/usr/local/share/dotnet/dotnet exec "/Users/redacted/Library/Caches/VisualStudio/17.0/MSBuild/36265_3/Sdks/Microsoft.NET.Sdk.Razor/build/netstandard2.0/../../tools/netcoreapp3.0/rzc.dll" generate
-s
/Users/redacted/Developer/repositories/bcee/Toolkit/MyCompany.Toolkit.Platform.Web/_Imports.razor
-r
_Imports.razor
-o
/Users/redacted/Developer/repositories/bcee/Toolkit/MyCompany.Toolkit.Platform.Web/obj/Debug/netstandard2.1/RazorDeclaration/_Imports.razor.g.cs
-k
component
-p
/Users/redacted/Developer/repositories/bcee/Toolkit/MyCompany.Toolkit.Platform.Web
-t
obj/Debug/netstandard2.1/MyCompany.Toolkit.Platform.Web.RazorComponents.declaration.json
-v
3.0
-c
Default
--root-namespace
MyCompany.Toolkit.Web
--csharp-language-version
8.0
--generate-declaration
The application to execute does not exist: '/Users/redacted/Library/Caches/VisualStudio/17.0/MSBuild/36265_3/Sdks/Microsoft.NET.Sdk.Razor/build/netstandard2.0/../../tools/netcoreapp3.0/rzc.dll'
/Users/redacted/Library/Caches/VisualStudio/17.0/MSBuild/36265_3/Sdks/Microsoft.NET.Sdk.Razor/build/netstandard2.0/Microsoft.NET.Sdk.Razor.Component.targets(106,5): error : rzc generate exited with code 129.
Done building target "RazorGenerateComponentDeclaration" in project "MyCompany.Toolkit.Platform.Web.csproj" -- FAILED.
Done building project "MyCompany.Toolkit.Platform.Web.csproj" -- FAILED.
Build FAILED.
The tools directory does not exists.
At fisrt, you said:
When I build from Visual Studio I have no issues.
The cause should be when you build from the Visual Studio. The framework your project used is .netstandard 2.0. You can check the project.csproj file and the SDK in the /usr/local/share/dotnet/sdk.
In addition, you can check this case which has the similar error as yours. According to it, if the .net version is not compatible with the xamarin will also get this error. dotnet/sdk/7.0.102 should be the .net 7 which is compatible with the .net maui not the xamarin. So you can't use the dotnet build the project.
You can try to find the right value of the MSBuildExtensionsPath and set it in the android and ios .csproj file according to this case which is about set the project's MSBuildExtensionsPath.
Finally, you can try the solution in this case which has the same error message.
The Xamarin tool chain was built upon Mono, so everything you triggered in VS for Mac is kindly processed by MSBuild for Mono (at Mac terminal you can use msbuild --version to learn more).
dotnet build, however, was designed exclusively for .NET Core based projects, so by default it won't be able to handle Xamarin projects, but only .NET MAUI.
As legacy Xamarin projects are going away soon, you should start to migrate to MAUI as soon as you can,
https://dotnet.microsoft.com/en-us/platform/support/policy/xamarin

Unable to compile llvm pass on Windows using Visual studio

Im learning how to use the llvm toolchain on Windows.
I compiled and installed llvm using the following cmake command
cmake -S llvm -B build -DLLVM_ENABLE_PROJECTS="clang;lld" -DLLVM_USE_LINKER=lld -DLLVM_TARGETS_TO_BUILD=X86 -DCMAKE_INSTALL_PREFIX="C:\llvm" -Thost=x64
Running the INSTALL project in the solution created in the build folder installed llvm in c:\llvm.
To test my llvm installation i created a new Visual Studio project and placed a Directory.build.props file in the project root with the following contents:
<Project>
<PropertyGroup>
<LLVMInstallDir>C:\llvm</LLVMInstallDir>
<LLVMToolsVersion>14.0.0</LLVMToolsVersion>
</PropertyGroup>
</Project>
I set the project toolchain to LLVM (clang-cl) in project settings and successfully compiled a hello world program.
Now i wanna use llvm for it's intended use and play around with some passes. So i downloaded https://github.com/tsarpaul/llvm-string-obfuscator.
Running cmake -Bbuild -DLLVM_DIR=C:\llvm\lib\cmake\llvm\ generated a Visual Studio solution in .\build.
So far so good i tought. This is similar to the steps required to compile llvm itself.
But running the BUILD_ALL project in the generated solution gave me 105 linker errors.
I have pasted the entire error output here: https://pastebin.com/TAizbAEi.
I have a feeling the required libraries in C:\llvm\lib are not visible to Visual Studio. But i have no idea how to proceed. Could anyone point me in the right direction on how to use llvm with visual studio correctly?
Solved by adding to the cmake file:
llvm_map_components_to_libnames(llvm_libs core)
target_link_libraries(LLVMStringObfuscator ${llvm_libs})
Now the dll build.
I still have problems using opt.exe
PS C:\Users\Administrator\source\repos> C:\llvm\bin\opt.exe -load-pass-plugin=.\11philip22\llvm-string-obfuscator\build\StringObfuscator\Release\LLVMStringObfuscator.dll -passes="string-obfuscator-pass"
C:\llvm\bin\opt.exe: .\11philip22\llvm-string-obfuscator\build\StringObfuscator\Release\LLVMStringObfuscator.dll:1:1: error: expected top-level entity
MZÉ    ╕ # ║ ┤ ═!╕L═!This program cannot be run in DOS mode.
But that's a new problem for another thread :)

Unknown Objective-C runtime 'microsoft'

I'm trying to compile an app with WinObjC. I'm using Visual Studio 2017 version 15.7.6 and WinObjC prerelease v0.2.180221 from NuGet.
The very first source file it tries to compile, and every subsequent one fails with the error message:
clang.exe : error : unknown or ill-formed Objective-C runtime 'microsoft'
What am I doing wrong?
You seems trying to use side loaded clang compiler, that not gonna work unfortunately, since for WinObjC have been used modified clang with custom ObjectiveC runtime added.
To build your project successfully, you must add latest WinObjC nuget packages of version v0.2.180221-dev-20180516000001 to your project along with this https://www.nuget.org/packages/WinObjC.Compiler/ compiler package, it includes proper clang forked from original clang v6.0.1. Supported VS version is v15.4.5-15.8.9
UPDATE 1
To use latest Visual Studio starting from v15.9 up to the current VS2019 v16.X, you might find useful this topic with guide how to modify your project to make it run.

Provide AndroidSDK path to mdtool on mac

I am building Xamarin.Adnroid project with an mdtool from rakefile as a step in TeamCity build configuration.
The call is:
/Applications/Xamarin\ Studio.app/Contents/MacOS/mdtool build "--configuration:Debug" -p:"Project.Droid" -t:Build "Project.sln"
This (and even if I set -p:AndroidSdkDirectory=/Users/user/AndroidSDK) gives an error:
error: The Android SDK could not be found, please set the path to it
in the Xamarin.Android SDKs settings panel.
I can use xbuild to build the project and specify the AndroidSDKPath via:
/usr/local/bin/xbuild Droid/Project.Droid.csproj /p:Configuration=Debug /t:SignAndroidPackage /p:AndroidSdkDirectory=/Users/user/AndroidSDK
but sine my solution hots both, Android and iOS projects, I'd like to be able to build both with mdtool.
Note that this question is unrelated to this one since the later of deals with the UI builds which work great in my case.
I suggest to open Xamarin Studio on the build host and configure the SDK path under Preferences > SDK Locations > Android. That should fix your problem.

What determines whether my .net core uses .csproj or project.json

I've got a machine with .NET Core 1.1.0 1.0.0-preview2-1-003182 installed as well as VisualStudio 2017 RC. When I create a project using "dotnet new -t Console" it requires a project.json file. When I create a .NET Core ConsoleApp in Visual Studio 2017 it requires the .csproj for build configuration. What determines this? I'd like to have one or the other, preferably consistent .csproj since project.json is deprecated for future versions as far as I can tell.
VisualStudio 2017 RC won't seem to build a self-contained executable, so I revert to the command line to attempt a "dotnet publish -t win10-x64" whereby I get the error that there is no project.json. So, even if I have my .csproj configured to build an .exe, I can't just build it.
The version of .NET Core Tools is the reason:
.csproj is used starting from .NET Core Tools Preview 3
Note: Visual Studio 2017 RC installs .NET Core Tools Preview 3 (or even Preview 4 now).
project.json is used in previous versions.
If you want to know with version of .NET Core Tools is used then go to root project folder and run next command:
dotnet --info
Possible output:
.NET Command Line Tools (1.0.0-preview2-1-003177)
Product Information:
Version: 1.0.0-preview2-1-003177
Commit SHA-1 hash: a2df9c2576
Runtime Environment:
OS Name: Mac OS X
OS Version: 10.12
OS Platform: Darwin
RID: osx.10.12-x64
If you have more then one version of .NET Core Tools on your machine, you can directly specify with version should be used for your project by global.json. Create (if not exists) this file in root folder and add "sdk" section. For example for Tools Preview 2:
{
...
"sdk": { "version": "1.0.0-preview2-1-003177" }
}
Also you may use dotnet-migrate command to convert your project.json to .csproj

Resources