Can't Build .Net Maui Android apk or aab file using Visual Studio Enterprise - xamarin.android

I'm following these instructions.
https://www.telerik.com/blogs/publishing-dotnet-maui-app-android
The Build process creates the dll and pdb file, but not the apk or aab files. I'm running Microsoft Visual Studio Enterprise 2022 (64-bit) - Current Version 17.4.3.
My keystore is here.
C:\Users\myname\AppData\Local\Xamarin\Mono for Android
Here is my code.
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net7.0-android33.0|AnyCPU'">
<AndroidKeyStore>True</AndroidKeyStore>
<AndroidSigningKeyStore>..\..\..\AppData\Local\Xamarin\Mono for Android\MyApp.keystore</AndroidSigningKeyStore>
<AndroidSigningKeyAlias>MyAlias</AndroidSigningKeyAlias>
<AndroidSigningKeyPass>MyPassword</AndroidSigningKeyPass>
<AndroidSigningStorePass>MyPassword</AndroidSigningStorePass>
</PropertyGroup>
I'm not getting an error message. Not sure what the problem is.
Any help is much appreciated.

#LiyunZhang-MSFT It worked! All I had to do is run this line in View - Terminal.
dotnet publish -f:net7.0-android -c:Release /p:AndroidSigningKeyPass=mypassword /p:AndroidSigningStorePass=mypassword
I changed this line for Android 33.
-f:net7.0-android33.0
The apk and aab files are located here.
bin\Release\net7.0-android33.0

Related

CMake - could not find any instance of Visual Studio [duplicate]

When I am trying to install CMake I get the error:
Visual Studio 15 2017 could not find any instance of Visual Studio.
I am using Windows 7 and Visual Studio 2017. The CMakeOutput.log file writes:
The system is: Windows - 6.1.7601 - AMD64
Any ideas?
I ran into the same error and performed the following steps to resolve the issue:
Open Visual Studio
Go to Tools -> Get Tools and Features
In the "Workloads" tab enable "Desktop development with C++"
Click Modify at the bottom right
These steps resulted in the "Visual C++ tools for CMake" feature being installed, but the other optional C++ features included in this workload may also helpful for what you are trying to do.
After the Visual Studio updater finishes installing try re-running the command. You may need to open a new command window.
In my case, I installed Visual Studio, selecting the workloads and modules that I wanted, but I ignored the request to reboot, assuming that shutting down the computer at the end of the day and restarting it the following day would suffice. I was wrong.
The following day I tried a cmake build and got the "could not find any instance of Visual Studio" error. After several attempts to resolve, I re-ran the installer, made no changes to the configuration, and clicked Modify. This time I let it reboot the computer. The reboot took a long time. After which my cmake build worked.
If you have already installed the workload Desktop development with C++ and still getting the following errors while using visual studio 2022 for flutter
Generator
Visual Studio 16 2019
could not find any instance of Visual Studio.
Building Windows application...
Exception: Unable to generate build files"
Solution: Follow these steps,
Edit your_flutter_path\packages\flutter_tools\lib\src\windows\build_windows.dart, and change the constant on line 28 from Visual Studio 16 2019 to Visual Studio 17 2022
Delete flutter_tools.stamp and flutter_tools.snapshot from your_flutter_path\bin\cache\
Run flutter clean in the project
I had the same issue "could not find any instance of Visual Studio"
but with Visual Studio 2019 (Community Edition) and I just had to configure the VS160COMNTOOLS variable so that CMake correctly detects Visual Studio.
export VS160COMNTOOLS="/c/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/Tools"
(cf https://cmake.org/cmake/help/latest/generator/Visual%20Studio%2016%202019.html)
With Visual Studio 15 2017, the variable you need should be VS150COMNTOOLS.
(cf https://cmake.org/cmake/help/latest/generator/Visual%20Studio%2015%202017.html)
NB: in my case, in a Travis-CI workflow, I installed Visual Studio using the commands (no need to reboot):
choco install visualstudio2019community
choco install visualstudio2019-workload-nativedesktop # required
With only the first package, CMake detection of VS2019 failed.
I was configuring a Jenkins build node and could successfully run CMake GUI manually but command line use or builds using the CMake plugin would fail with:
Visual Studio 16 2019 could not find instance of Visual Studio.
-A x64 parameter was added with no change in result.
The problem was that CMake could not determine the Windows SDK version.
By adding CMAKE_SYSTEM_VERSION parameter CMake was then able to find Visual Studio.
-D CMAKE_SYSTEM_VERSION=10.0.18362.0 (use your windows SDK version)
Environment:
windows 10 system build: 19042
CMAKE 3.19.4
VS 2019 Professional 16.8.4
Jenkins 2.235.1
Full command line that worked:
"C:\Program Files\CMake\bin\cmake" -G "Visual Studio 16 2019" -D CMAKE_BUILD_TYPE=Release -A x64 -D CMAKE_SYSTEM_VERSION=10.0.18362.0
When using VS 2017, be aware that this is really VS 2015, and CMake identified it as VS 2017 2022 which is not the version of VS 2017 I had, that gave me this error. So the conclusion I offer is to try different versions, specifically the 2015 one.
I had a similar issue where installing libzmq in my npm project was throwing the same error and that wasn't getting solved by enabling "msbuild" under "Desktop development with C++" in the Visual Studio installer.
My solution ended up being to reinstall the Windows build tools for npm with the following command.
npm install --global windows-build-tools
Note: Remember to run the command prompt (or whatever terminal you are using) as admin before running this.
If the CMake used to work with the installed Visual Studio and is broken someday, then the problem could be VS requires system reboot to complete some update.
For quick verification, rename HKLM\SOFTWARE\WOW6432Node\Microsoft\VisualStudio\Setup\Reboot to like HKLM\SOFTWARE\WOW6432Node\Microsoft\VisualStudio\Setup\Reboot.bak, then re-run cmake which should succeed. Don't forget to rename the registry back and reboot the system if this is the problem.
In my case, I was selecting different version of visual studio in that configuration dialog box whereas I installed different version.
Do select the same version.
Above solutions did not solve this issue for me. After installing node.js from https://nodejs.org/en/download/ apparently a correct version of windows-build-tools was installed
I reinstalled the Visual Studio 2019(my former one is 2017 version ) with all those settings required(my cmake version is 3.23.0),and it works. So try to install different versions.
In my case, the problem was gone after I deleted the previous cmake result directory and then ran cmake again.
if you have installed two or more Windows 10 SDK, delete them excluding latest one.
Try downloading the windows-build-tools package.
npm install --global --production windows-build-tools --vs2015
This step should be the end-all-be-all solution to fixing node-gyp problems. For most people, that’s true. NPM has a package called windows-build-tools that should automatically install everything you need to get node-gyp working, including the Microsoft build tools, compilers, Python, and everything else required to build native Node modules on Windows.

How can I build Visual Studio 2019 projects on Travis CI?

Travis CI recently added a Windows OS option to its build system. Unfortunately, the preinstalled packages only include Visual Studio 2017.
How can I build Visual Studio 2019 projects (such as .Net Core 3.1 and v142 build tools projects) on Travis?
The key to using updated build tools is Chocolatey, the Windows package manager. As long as the toolset is available on Chocolatey, you can install it on your Travis VM.
For .Net Core, that means installing the dotnetcore-sdk package.
For VC++ build tools, there is the visualstudio2019buildtools package, but note you will have to opt in to the Microsoft.VisualStudio.Component.VC.Tools.x86.x64 feature. See below for syntax. A full list of features is available in the Build Tools component directory.
Here's a full .travis.yml file for a VS 2019 solution containing a C++ project, a .Net Standard 2.0 project and a .Net Core 3.1 project. The test project makes use of the unmanaged DLL.
os: windows
language: cpp
env:
- MSBUILD_PATH="C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin"
install:
- choco install visualstudio2019buildtools --package-parameters "--add Microsoft.VisualStudio.Component.VC.Tools.x86.x64"
- choco install dotnetcore-sdk
- dotnet restore
script:
- export PATH=$MSBUILD_PATH:$PATH
- MSBuild.exe -p:Configuration=Release -p:Platform=x64 CppProject/CppProject.vcxproj
- dotnet build --configuration Release
- dotnet test DotNetProject.Tests/bin/Release/netcoreapp3.1/DotNetProject.Tests.dll

'vc_redist.x64 does not install in microsoft/nanoserver image

I want to use microsoft/nanoserver as base image for my requirement and want to install 'vc_redist.x64' package into it but I am not able to install as it returns some error as shown below:
and this is my Dockerfile:
FROM microsoft/nanoserver
MAINTAINER <org name>
ADD . /
CMD ["powershell", "c:/scripts/start.ps1"]
ADD https://download.microsoft.com/download/6/A/A/6AA4EDFF-645B-48C5-81CC-ED5963AEAD48/vc_redist.x64.exe /vc_redist.x64.exe
RUN C:\vc_redist.x64.exe /quiet /install
However if I use 'microsoft/windowsservercore' the base image size increases rapidly and it goes to 12+ GB. having large base image size does not fit in my requirement.
Is there any way to install 'vc_redist.x64' in 'microsoft/nanoserver' with its dependencies?
Any help is much appreciated.
Visual C++ Redistributable Packages cannot be installed in NanoServer.
However, you can use the binary dlls manually. The redistributable files are installed with Visual Studio.
Steps:
Open Visual Studio Installer, make sure you check Desktop Development with C++. At right details panel, check all versions you want to install:
MSVC v143 - VS 2022
MSVC v142 - VS 2019
MSVC v141 - VS 2017
MSVC v140 - VS 2015
Find your VS installation folder, for example, VS2022 should be like C:\Program Files\Microsoft Visual Studio\2022\Community and VS2019 should be C:\Program Files (x86)\Microsoft Visual Studio\2019\Community. Then go to the CRT folder.
I have installed VS2022 and want to use MSVC v142, so the full path should be:
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Redist\MSVC\14.29.30133\onecore\x64\Microsoft.VC142.CRT
Copy everything under this folder to your application's local folder, or C:\Windows\System32 in your NanoServer image.

Building UWP app in command line (using MSBUILD)

I am trying to build UWP app (targeting 16299) from command line from Jenkins setup.
The system has only VS build tools 2017.
used this command to build
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\msbuild.exe" /t:Rebuild /p:Configuration=Release;AppxBundle=Always;AppxBundlePlatforms="x86\x64\ARM" /p:BuildAppxUploadPackageForUap=true SOLUTION_FILE.sln
error MSB4226: The imported project "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\Microsoft\WindowsXaml\v15.0\Microsoft.Windows.UI.Xaml.CSharp.targets" was not found. Also, tried to find "Microsoft\WindowsXaml\v15.0\Microsoft.Windows.UI.Xaml.CSharp.targets" in the fallback search path(s) for $(MSBuildExtensionsPath) - "C:\Program Files (x86)\MSBuild" . These search paths are defined in "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\MSBuild.exe.Config". Confirm that the path in the declaration is correct, and that the file exists on disk in one of the search paths.
Another issue found is nuget is not restoring any package, so updated nuget to 4.4.1 then I got the error
MSBuild auto-detection: using msbuild version '15.5.180.51428' from 'C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\bin'.
Nothing to do. None of the projects in this solution specify any packages for NuGet to restore.
same issue with nuget 4.6.0 also
I tried by adding following in project file
<PropertyGroup>
<RestoreProjectStyle>PackageReference</RestoreProjectStyle> </PropertyGroup>
same issue with msbuild and nuget, anyone succeed in building UWP in Jenkins?
Update 05-01-2015
Followed instruction according to answer.
Copied NuGet folder
Copied the "WindowsXaml" folder.
Used MSbuild restore instead of Nuget restore to fix msbuild trying to find packages in "C:\WINDOWS\system32\config\systemprofile.nuget\packages\"
With all these changes no more issues in build,
But the appx bundle is not present. may be individual appx for x86/x64/ARM has to be created and then some kind of merging i s required.
so need further investigations
From the directory path that you have for MSBuild, I see that you may have installed MSBuildTools installer instead of the community, professional,... editions.
I tried that before and found that it's incomplete and doesn't have all dependencies for building Uwp tools, take a look at some of the comments here about the issues.
First Workaround: You can install Uwp Workload from VS Community or Professional as it has all dependencies, till Microsoft fix the issues in BuildTools installer.
Bonus: if you want to run the installer from command line, you can compose command line like that:
vs_installer.exe --installPath "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools" ^
--add Microsoft.VisualStudio.Workload.Universal ^
--add Microsoft.VisualStudio.Component.Windows10SDK.14393 ^
--add Microsoft.Component.MSBuild ^
--passive --wait --norestart
The longer workaround, I managed to install other dependencies but I believe it's kind of hassle if you are automating this installation, snippets from this article
Copy the Sdks folder from a machine that has VS2017 installed at:
c:\Program Files(x86)\Visual Studio\2017\Professional\Build MSBuild\Sdks
to your build machine at:
c:\Program Files(x86)\Visual Studio\2017\Build Tools\MSBuild\Sdks
And for the nuggets issue:
Copying the NuGet import files will do the tr Again, from a machine
with VS2017, copy the following folder: C:\Program Files
(x86)\Microsoft Visual
Studio\2017\Professional\Common7\IDE\CommonExtensions\Microsoft\NuGet
to your build machine at: C:\Program Files (x86)\Microsoft Visual
Studio\2017\BuildTools\Common7\IDE\CommonExtensions\Microsoft\NuGet
Note: If you come by this later and found that Microsoft fixed the issues related to Uwp in MSBuildTools installer, please leave a comment about it in this answer to update it.

don't have apk in Bin and cannot build app in monodevelop when update Mono for Android 4.1

After update Mono for Android from 4.0 -> 4.1 ,I have problems:
In Visual Studio : when I start application , it doesn't run application in emulator(I only see message notification at left corner Build successful!) and I cannot see .apk file in Bin
In Mono develope :When I build this app it have error Error MSB4019: The imported project "C:\Program Files (x86)\MonoDevelop\AddIns\BackendBindings\MSBuild\Novell\Novell.MonoDroid.CSharp.targets" was not found. Confirm that the path in the declaration is correct, and that the file exists on disk. (MSB4019)
Does anyone know what might generate these errors?
In VS, you probably need to turn on "Deploy" for your project:
http://docs.xamarin.com/android/Releases/Mono_For_Android_4/Mono_for_Android_4.1.0#Non-modal_Deployment

Resources