Click Once Build Different Between Visual Studio and msbuild - wpf

I am working on a Click Once Deployment Application. I can produce a working build by using the publish menu inside Visual Studio 2022. When I build the application outside of the Visual Studio using MSBuild it successfully installs but fails to launch. The goal is to in turn build that application with Azure DevOps Pipelines.
This is the what I run with MSBuild
msbuild CompanyPortal.Desktop.csproj -t:publish -p:PublishDir="C:/Users/rebel/Desktop/CompanyPortalBuild" /p:PublishProfile=ClickOnceProfile
Here is my publish profile
<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ApplicationRevision>3</ApplicationRevision>
<ApplicationVersion>1.0.0.*</ApplicationVersion>
<BootstrapperEnabled>True</BootstrapperEnabled>
<Configuration>Release</Configuration>
<CreateWebPageOnPublish>False</CreateWebPageOnPublish>
<GenerateManifests>True</GenerateManifests>
<Install>True</Install>
<InstallFrom>Disk</InstallFrom>
<IsRevisionIncremented>True</IsRevisionIncremented>
<IsWebBootstrapper>False</IsWebBootstrapper>
<ManifestCertificateThumbprint>xxxxxxxxxxxxxxxxxxx</ManifestCertificateThumbprint>
<ManifestKeyFile>CompanyPortal.Desktop_TemporaryKey.pfx</ManifestKeyFile>
<MapFileExtensions>True</MapFileExtensions>
<OpenBrowserOnPublish>False</OpenBrowserOnPublish>
<Platform>Any CPU</Platform>
<PublishDir>bin\publish\</PublishDir>
<PublishUrl>bin\publish\</PublishUrl>
<PublishProtocol>ClickOnce</PublishProtocol>
<PublishReadyToRun>False</PublishReadyToRun>
<PublishSingleFile>False</PublishSingleFile>
<RuntimeIdentifier>win-x86</RuntimeIdentifier>
<SelfContained>True</SelfContained>
<SignatureAlgorithm>sha256RSA</SignatureAlgorithm>
<SignManifests>False</SignManifests>
<TargetFramework>net6.0-windows</TargetFramework>
<UpdateEnabled>False</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateRequired>False</UpdateRequired>
<WebPageFileName>Publish.html</WebPageFileName>
</PropertyGroup>
</Project>
Below is the csproj of the program I am trying to build and deploy using ClickOnce. This is a WPF using WebView to Display a Blazor wasm application
<Project Sdk="Microsoft.NET.Sdk.Razor">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
<IsShippingPackage>false</IsShippingPackage>
<AssemblyVersion>2.9.96</AssemblyVersion>
<FileVersion>2.9.96</FileVersion>
<Version>2.9.96</Version>
<ApplicationIcon>wwwroot\favicon.ico</ApplicationIcon>
<PackageIcon>Company_Portal_Icon_512.png</PackageIcon>
<ApplicationManifest>app.manifest</ApplicationManifest>
<RuntimeIdentifier>win-x86</RuntimeIdentifier>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebView.Wpf" Version="6.0.101-preview.11.2349" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CompanyPortal.Components\CompanyPortal.Components.csproj" />
</ItemGroup>
<ItemGroup>
<Content Update="wwwroot\**">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<None Update="Company_Portal_Icon_512.png">
<Pack>True</Pack>
</None>
</ItemGroup>
</Project>
Is there something I am missing? That would cause the build to work perfectly when it's built from Visual Studio but not from MSBuild?

Related

How to set which package to join into static application dll?

I create .net with dotnet cli and visual code. how to tell msbuild to join other dll into application.dll or as static dll? currently when i compile, all package as dynamic. it fills output folder with package dll. i want to select which package join into application.dll.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.0-preview.7.22376.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.0-preview.7.22376.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="Selenium.WebDriver" Version="4.4.0" />
</ItemGroup>
</Project>

How can I add a reference to PresentationCore in Visual Studio 2019?

How can I add a reference to PresentationCore to an existing .NET 5 class library?
Set TargetFramework and UseWPF:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0-windows</TargetFramework>
<UseWPF>true</UseWPF>
</PropertyGroup>
</Project>

'Could not load type 'System.IO.Compression.ZipFile' from assembly 'Newtonsoft.Json'

I'm using System.IO.Compression.ZipFile NuGet to extract .zip archive. The code looks like this:
ZipFile.ExtractToDirectory(gameFolderAbsolutePath + api, gameFolderAbsolutePath, true);
There is no issue when using application as compiled in any configuration (Debug / Release). The problem occurs when the application is run after it's publish, with these settings:
After this published app is run it crashes at the code line shown above giving this exception message: System.TypeLoadException: 'Could not load type 'System.IO.Compression.ZipFile' from assembly 'Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'.'
I'm not aware of why should have System.IO.Compression.ZipFile look for something in Newtonsoft.Json tho.
Publish.pubx.xml:
<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration>Release</Configuration>
<Platform>Any CPU</Platform>
<PublishDir>P:\ReleaseCandidate\installer-binaries\data</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RuntimeIdentifier>win-x86</RuntimeIdentifier>
<SelfContained>true</SelfContained>
<PublishSingleFile>True</PublishSingleFile>
<PublishReadyToRun>True</PublishReadyToRun>
<PublishTrimmed>True</PublishTrimmed>
</PropertyGroup>
</Project>
PackageReferences from .csproj:
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="3.1.6" />
<PackageReference Include="Microsoft.Extensions.PlatformAbstractions" Version="1.1.0" />
<PackageReference Include="NLog" Version="4.7.3" />
<PackageReference Include="RestSharp" Version="106.11.4" />
<PackageReference Include="RestSharp.Serializers.NewtonsoftJson" Version="106.11.4" />
<PackageReference Include="System.IO.Compression.ZipFile" Version="4.3.0" />
<PackageReference Include="System.Net.NameResolution" Version="4.3.0" />
<PackageReference Include="System.Runtime.InteropServices" Version="4.3.0" />
</ItemGroup>
Even tho I have tried many times to publish the application with 'Trim unused assemblies (in preview)' checkbox unchecked, it turned out it haven't been taken into process. The problem had been resolved after removing the redundant tags from the .csproj.

Android application manager shows wrong app name

Does anyone know why the application manager, found by going to settings->application manager, is showing the wrong name for my application? I installed my app twice under different names and with different application package names. I can see both named applications under the apps page, but the application manager is showing them as the same name. I need to know which is which so I can force close and uninstall the correct version of my application. Any ideas?
Here's the manifest of the DEMO version of my application, where string/app_name = package_DEMO:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="my.apps.package_DEMO"
android:versionCode="1"
android:versionName="0.0">
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="10"/>
<application android:label="#string/app_name"
android:name="my.apps.package.MyApplication"
android:icon="#drawable/ic_launcher"
android:theme="#style/AppTheme"
android:launchMode="singleTask"
android:debuggable="true">
<activity android:label="#string/app_name"
android:configChanges="orientation|keyboardHidden"
android:name="my.apps.package.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:label="#string/app_name"
android:configChanges="orientation|keyboardHidden"
android:name="my.apps.package.SettingsActivity">
</activity>
</application>
</manifest>
And the original's manifest, where string/app_name = package:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="my.apps.package"
android:versionCode="1"
android:versionName="0.0">
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="10"/>
<application android:label="#string/app_name"
android:name="my.apps.package.MyApplication"
android:icon="#drawable/ic_launcher"
android:theme="#style/AppTheme"
android:launchMode="singleTask"
android:debuggable="true">
<activity android:label="#string/app_name"
android:configChanges="orientation|keyboardHidden"
android:name="my.apps.package.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:label="#string/app_name"
android:configChanges="orientation|keyboardHidden"
android:name="my.apps.package.SettingsActivity">
</activity>
</application>
</manifest>
I had this problem - i.e. that of the app name showing up incorrectly in Settings->Apps
I managed to fix it by rebooting the device.
My guess is that the android application manager was caching the 'old' name until a reboot. I confirmed this by changing the app name and redeploying - the old name shows in settings->aps until a reboot.
It is probably because of your manifest file. If you copied your code and only refactored the package names, eclipse does not change the name of your application in the manifest file.
Either change directly, or use your string.xml files
android:label="#string/app_name"
you can add android:label="YOUR NAME APP"
<application
android:label="YOUR NAME APP"
android:allowBackup="true"
android:icon="#drawable/logo">
You can uninstall the package name by connecting your phone to the pc...
Go to the command prompt
adb uninstall packagename
so if you want to delete an an app with package name com.example.test
Type : adb uninstall com.example.test in command prompt...
Note :
adb should in the system path
or else run this command from your sdkfolder/platform-tools/
I just uninstalled, cleaned, and reinstalled for like the 50th time, and magically the app names are different under the application manager. This must be a system bug, because both versions of the app were showing different names in the activity labels, and under the "apps" page on the device eariler. I'll try seeing if I can reproduce it again.

Manual XBAP publishing

I found a method to manually publish a regular WPF Application, but i need the same instructions for a WPF Browser app instead. Here is the regular WPF App howto: http://msdn.microsoft.com/en-us/library/xc3tc5xx(VS.80).aspx . If anyone knows what changes I need to make to my mage commands to make it work for XBAP please let me know. Thanks.
I had to alter the name of the default "Application Files" folder for one of our customers who doesn't like spaces in file or folder names and this meant re-signing the xbap after the publish. Here's the msbuild script I use to automate the process:
<Target Name="PublishWebsite" DependsOnTargets="CleanWebsiteOutputPath;CleanOutputPath;CleanWebsiteReleasePath">
<!-- Compile Website -->
<MSBuild Projects=".\Some.Namespace.Web.Site\Some.Namespace.UI.Web.Site.csproj" Targets="Clean;Rebuild;" Properties="Configuration=Release" />
<!-- Copy Website files to release folder -->
<ItemGroup>
<SiteFiles Include="Some.Namespace.UI.Web.Site/**/*.*" />
</ItemGroup>
<Copy SourceFiles="#(SiteFiles)" DestinationFolder="..\rel\Website\%(RecursiveDir)" />
<!-- Remove source code and source control files from website -->
<CallTarget Targets="CleanWebsiteAfterPublish" />
<Message Text="Website Published" />
<!-- Rename "Application Files" folder and re-sign the xbap -->
<StringReplace Pattern="\." InputString="$(ApplicationVersion)" Replace="_">
<Output PropertyName="VersionUnderscored" TaskParameter="Result" />
</StringReplace>
<MSBuild Projects=".\Some.Namespace.UI.WPF\Some.Namespace.UI.WPF.csproj" Targets="Publish" Properties="Configuration=Release;" />
<Exec Command="move "..\bin\Release\app.publish\Application Files" "..\bin\Release\app.publish\ApplicationFiles"" />
<Exec Command="$(MageExe) -update ..\bin\Release\app.publish\SomeApp.xbap –AppManifest ..\bin\Release\app.publish\ApplicationFiles\SomeApp_$(VersionUnderscored)\SomeApp.exe.manifest -wpf true -cf ..\ext\Signing\SomeApp.pfx -pwd password" />
<!-- Move published files to Release directory -->
<ItemGroup>
<XbapPublishFiles Include="..\bin\Release\app.publish\**\*.*" />
</ItemGroup>
<Copy SourceFiles="#(XbapPublishFiles)" DestinationFiles="#(XbapPublishFiles->'..\rel\Website\%(RecursiveDir)%(Filename)%(Extension)')" />
<Message Text="XBAP Published" />
</Target>

Resources