编辑 #1 开始
要复制这个:
- 创建一个新的“vanilla”WPF 应用程序寻址 .Net Core 3.1
- 向解决方案添加一个
Windows Application Packaging Project
(按照在 Visual Studio 中为 MSIX 打包设置桌面应用程序中提到的步骤) - 尝试“部署”到 UNC 路径...
编辑 #1 结束
我正在将 WPF .net 框架应用程序转换为 .net core 3.1。此应用程序是一个“内部”工具,我们一直使用 ClickOnce 将其部署在共享的 UNC 路径上。很简单....
我现在用 .Net Core 重写了它,需要部署它。发现“ClickOnce”不再可用,我知道我必须走“MSIX”路线。文档看起来应该很简单,但我想我遗漏了一些东西......
1 - 我不得不将我的开发人员设置从“侧边栏”更改为“开发人员模式” 2 - 它在我的机器上构建良好,但在 Azure DevOps 上失败 3 - 我如何实际部署它......?
让我们依次看一下。
1 - 侧栏 => 开发者模式问题
我将一个新的 Windows 应用程序打包项目添加到我的解决方案中,为目标版本和最低版本选择 Windows 版本 1909,并将我的 WPF 应用程序设置为入口点。我尝试运行它,它迫使我从“侧边栏”更改为“开发者模式”。
这是否只影响我作为开发人员......如果是这样,那很好。我怀疑最终的最终用户会想要这样做。
2 - Azure DevOps 构建管道失败
在本地,它编译得很好,即使在我将所有警告设置为错误并运行 FxCop 的发布模式下也是如此。将其推送到 Azure 并显示:
[错误]C:\Program Files\dotnet\sdk\3.1.201\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(234,5): Error NETSDK1047: Assets file 'd:\a\1 \s\MyApp\MyApp\obj\project.assets.json' 没有 '.NETCoreApp,Version=v3.1/win-x86' 的目标。
确保恢复已运行,并且您已在项目的 TargetFrameworks 中包含“netcoreapp3.1”。
您可能还需要在项目的 RuntimeIdentifiers 中包含“win-x86”。
好的
- 我的 YAML 文件在成功构建之前有一个“还原 NuGet 包”步骤。
- 我在我的 SKD 项目文件中查找我的应用程序,我看到了
<TargetFramework>netcoreapp3.1</TargetFramework>
- 关于“RuntimeIdentifiers”,我发现链接Additions to the csproj format for .NET Core所以
<RuntimeIdentifiers>win-x64;win-x86</RuntimeIdentifiers>
立即添加在下面<TargetFramework>netcoreapp3.1</TargetFramework>
(我应该更具体地使用win10-x64;win10-x86
吗?)
无论哪种方式,这都失败了,消息略有不同:
正在构建的项目“MSIL”的处理器架构与参考“我的 dll 的路径”、“x86”的处理器架构不匹配。这种不匹配可能会导致运行时失败。请考虑通过配置管理器更改项目的目标处理器体系结构,以便在项目和参考之间对齐处理器体系结构,或者依赖具有与项目的目标处理器体系结构匹配的处理器体系结构的参考。
3 - 我如何实际部署它?
来自MSIX:在 Windows 上部署桌面应用程序的现代方式它指出:
要生成实际的 MSIX 包,Project | 下提供了一个向导。商店 | 在 Visual Studio 中创建应用程序包。
我的机器上没有……我什至安装了 Visual Studio 工作负载“通用 Windows 平台开发”。我可以在“构建”菜单下看到“部署”……但就是这样……我将 UNC 路径放在哪里?
我想我错过了一些相当基本的东西......
我的 CSPROJ 的相关部分是
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RuntimeIdentifiers>win-x64;win-x86</RuntimeIdentifiers>
<UseWPF>true</UseWPF>
</PropertyGroup>
打包项目是:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' < '15.0'">
<VisualStudioVersion>15.0</VisualStudioVersion>
</PropertyGroup>
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|x86">
<Configuration>Debug</Configuration>
<Platform>x86</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x86">
<Configuration>Release</Configuration>
<Platform>x86</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|ARM">
<Configuration>Debug</Configuration>
<Platform>ARM</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|ARM">
<Configuration>Release</Configuration>
<Platform>ARM</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|ARM64">
<Configuration>Debug</Configuration>
<Platform>ARM64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|ARM64">
<Configuration>Release</Configuration>
<Platform>ARM64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|AnyCPU">
<Configuration>Debug</Configuration>
<Platform>AnyCPU</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|AnyCPU">
<Configuration>Release</Configuration>
<Platform>AnyCPU</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup>
<WapProjPath Condition="'$(WapProjPath)'==''">$(MSBuildExtensionsPath)\Microsoft\DesktopBridge\</WapProjPath>
</PropertyGroup>
<Import Project="$(WapProjPath)\Microsoft.DesktopBridge.props" />
<PropertyGroup>
<ProjectGuid>08b169a2-6461-440b-afa1-ca35c7d98aa7</ProjectGuid>
<TargetPlatformVersion>10.0.18362.0</TargetPlatformVersion>
<TargetPlatformMinVersion>10.0.18362.0</TargetPlatformMinVersion>
<DefaultLanguage>en-US</DefaultLanguage>
<AppxPackageSigningEnabled>True</AppxPackageSigningEnabled>
<EntryPointProjectUniqueName>..\MyApp\MyApp.csproj</EntryPointProjectUniqueName>
<PackageCertificateThumbprint>01C08F1E21D5624A484DB362BE4F056504B825CC</PackageCertificateThumbprint>
</PropertyGroup>
<ItemGroup>
<AppxManifest Include="Package.appxmanifest">
<SubType>Designer</SubType>
</AppxManifest>
</ItemGroup>
<ItemGroup>
<Content Include="Images\SplashScreen.scale-200.png" />
<Content Include="Images\LockScreenLogo.scale-200.png" />
<Content Include="Images\Square150x150Logo.scale-200.png" />
<Content Include="Images\Square44x44Logo.scale-200.png" />
<Content Include="Images\Square44x44Logo.targetsize-24_altform-unplated.png" />
<Content Include="Images\StoreLogo.png" />
<Content Include="Images\Wide310x150Logo.scale-200.png" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\MyApp\MyApp.csproj">
<SkipGetTargetFrameworkProperties>True</SkipGetTargetFrameworkProperties>
</ProjectReference>
</ItemGroup>
<Import Project="$(WapProjPath)\Microsoft.DesktopBridge.targets" />
</Project>
(我可以/应该删除我认为不相关的对“DEBUG”和“ARM”的引用吗??)
清单是
<?xml version="1.0" encoding="utf-8"?>
<Package
xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
IgnorableNamespaces="uap rescap">
<Identity
Name="46aebba6-d403-4412-89c0-05279b36e54e"
Publisher="CN=MyCompany"
Version="2020.5.0.0" />
<Properties>
<DisplayName>MyApp</DisplayName>
<PublisherDisplayName>MyCompany</PublisherDisplayName>
<Logo>Images\StoreLogo.png</Logo>
</Properties>
<Dependencies>
<TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.14393.0" MaxVersionTested="10.0.14393.0" />
</Dependencies>
<Resources>
<Resource Language="x-generate"/>
</Resources>
<Applications>
<Application Id="App"
Executable="$targetnametoken$.exe"
EntryPoint="$targetentrypoint$">
<uap:VisualElements
DisplayName="MyApp.Package"
Description="MyApp.Package"
BackgroundColor="transparent"
Square150x150Logo="Images\Square150x150Logo.png"
Square44x44Logo="Images\Square44x44Logo.png">
<uap:DefaultTile Wide310x150Logo="Images\Wide310x150Logo.png" />
<uap:SplashScreen Image="Images\SplashScreen.png" />
</uap:VisualElements>
</Application>
</Applications>
<Capabilities>
<Capability Name="internetClient" />
<rescap:Capability Name="runFullTrust" />
</Capabilities>
</Package>
谢谢!