Skip to content

Commit

Permalink
update webview2
Browse files Browse the repository at this point in the history
catch webview2 version errors.
  • Loading branch information
lovettchris committed Sep 20, 2024
1 parent 728dc07 commit b472fb3
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 50 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dotnet-desktop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ jobs:
- name: Build the application
run: |
echo namespace XmlNotepad { public partial class AppAnalytics { private const string ApiKey=""; } } >> .\src\Model\ApiKey.cs
msbuild ./src/XmlNotepad.sln /p:Configuration=$env:Configuration /verbosity:minimal
msbuild ./src/XmlNotepad.sln /p:Configuration=$env:Configuration "/p:Platform=Any CPU" /verbosity:minimal
env:
Configuration: ${{ matrix.configuration }}
79 changes: 50 additions & 29 deletions src/Application/Application.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@
<ApplicationIcon>Resources\XmlNote.ico</ApplicationIcon>
<StartupObject>XmlNotepad.Program</StartupObject>
<AssemblyOriginatorKeyFile>$(MyKeyFile)</AssemblyOriginatorKeyFile>
<FileUpgradeFlags></FileUpgradeFlags>
<UpgradeBackupLocation></UpgradeBackupLocation>
<FileUpgradeFlags>
</FileUpgradeFlags>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<OldToolsVersion>3.5</OldToolsVersion>
<TargetFrameworkProfile />
<IsWebBootstrapper>false</IsWebBootstrapper>
<NuGetPackageImportStamp></NuGetPackageImportStamp>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
<PublishUrl>..\..\publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
Expand Down Expand Up @@ -68,7 +71,8 @@
<ManifestCertificateThumbprint>50D58171E20BB6188B199ACA7C20A26DA0DFBF35</ManifestCertificateThumbprint>
</PropertyGroup>
<PropertyGroup>
<ManifestTimestampUrl></ManifestTimestampUrl>
<ManifestTimestampUrl>
</ManifestTimestampUrl>
</PropertyGroup>
<PropertyGroup>
<GenerateManifests>true</GenerateManifests>
Expand All @@ -77,14 +81,14 @@
<ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Web.WebView2.Core, Version=1.0.2478.35, Culture=neutral, PublicKeyToken=2a8ab48044d2601e, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Web.WebView2.1.0.2478.35\lib\net45\Microsoft.Web.WebView2.Core.dll</HintPath>
<Reference Include="Microsoft.Web.WebView2.Core, Version=1.0.2739.15, Culture=neutral, PublicKeyToken=2a8ab48044d2601e, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Web.WebView2.1.0.2739.15\lib\net462\Microsoft.Web.WebView2.Core.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Web.WebView2.WinForms, Version=1.0.2478.35, Culture=neutral, PublicKeyToken=2a8ab48044d2601e, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Web.WebView2.1.0.2478.35\lib\net45\Microsoft.Web.WebView2.WinForms.dll</HintPath>
<Reference Include="Microsoft.Web.WebView2.WinForms, Version=1.0.2739.15, Culture=neutral, PublicKeyToken=2a8ab48044d2601e, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Web.WebView2.1.0.2739.15\lib\net462\Microsoft.Web.WebView2.WinForms.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Web.WebView2.Wpf, Version=1.0.2478.35, Culture=neutral, PublicKeyToken=2a8ab48044d2601e, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Web.WebView2.1.0.2478.35\lib\net45\Microsoft.Web.WebView2.Wpf.dll</HintPath>
<Reference Include="Microsoft.Web.WebView2.Wpf, Version=1.0.2739.15, Culture=neutral, PublicKeyToken=2a8ab48044d2601e, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Web.WebView2.1.0.2739.15\lib\net462\Microsoft.Web.WebView2.Wpf.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Win32.Registry, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Win32.Registry.5.0.0\lib\net461\Microsoft.Win32.Registry.dll</HintPath>
Expand Down Expand Up @@ -172,7 +176,8 @@
<Compile Include="FormSearch.Designer.cs">
<DependentUpon>FormSearch.cs</DependentUpon>
</Compile>
<Compile Include="Program.cs"></Compile>
<Compile Include="Program.cs">
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="XmlDiffWrapper.cs" />
<EmbeddedResource Include="FormGotoLine.resx">
Expand Down Expand Up @@ -301,64 +306,80 @@
<ItemGroup>
<PublishFile Include="Samples\basket.xml">
<Visible>False</Visible>
<Group></Group>
<TargetPath></TargetPath>
<Group>
</Group>
<TargetPath>
</TargetPath>
<PublishState>Include</PublishState>
<IncludeHash>True</IncludeHash>
<FileType>File</FileType>
</PublishFile>
<PublishFile Include="Samples\basket.xsd">
<Visible>False</Visible>
<Group></Group>
<TargetPath></TargetPath>
<Group>
</Group>
<TargetPath>
</TargetPath>
<PublishState>Include</PublishState>
<IncludeHash>True</IncludeHash>
<FileType>File</FileType>
</PublishFile>
<PublishFile Include="Samples\Employee.xml">
<Visible>False</Visible>
<Group></Group>
<TargetPath></TargetPath>
<Group>
</Group>
<TargetPath>
</TargetPath>
<PublishState>Include</PublishState>
<IncludeHash>True</IncludeHash>
<FileType>File</FileType>
</PublishFile>
<PublishFile Include="Samples\Employee.xsd">
<Visible>False</Visible>
<Group></Group>
<TargetPath></TargetPath>
<Group>
</Group>
<TargetPath>
</TargetPath>
<PublishState>Include</PublishState>
<IncludeHash>True</IncludeHash>
<FileType>File</FileType>
</PublishFile>
<PublishFile Include="Samples\Hamlet.xml">
<Visible>False</Visible>
<Group></Group>
<TargetPath></TargetPath>
<Group>
</Group>
<TargetPath>
</TargetPath>
<PublishState>Include</PublishState>
<IncludeHash>True</IncludeHash>
<FileType>File</FileType>
</PublishFile>
<PublishFile Include="Samples\rss.xml">
<Visible>False</Visible>
<Group></Group>
<TargetPath></TargetPath>
<Group>
</Group>
<TargetPath>
</TargetPath>
<PublishState>Include</PublishState>
<IncludeHash>True</IncludeHash>
<FileType>File</FileType>
</PublishFile>
<PublishFile Include="Samples\rsspretty.xsl">
<Visible>False</Visible>
<Group></Group>
<TargetPath></TargetPath>
<Group>
</Group>
<TargetPath>
</TargetPath>
<PublishState>Include</PublishState>
<IncludeHash>True</IncludeHash>
<FileType>File</FileType>
</PublishFile>
<PublishFile Include="Samples\willy.xsl">
<Visible>False</Visible>
<Group></Group>
<TargetPath></TargetPath>
<Group>
</Group>
<TargetPath>
</TargetPath>
<PublishState>Include</PublishState>
<IncludeHash>True</IncludeHash>
<FileType>File</FileType>
Expand Down Expand Up @@ -398,11 +419,11 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<Import Project="..\packages\Microsoft.Web.WebView2.1.0.2478.35\build\Microsoft.Web.WebView2.targets" Condition="Exists('..\packages\Microsoft.Web.WebView2.1.0.2478.35\build\Microsoft.Web.WebView2.targets')" />
<Import Project="..\packages\Microsoft.Web.WebView2.1.0.2739.15\build\Microsoft.Web.WebView2.targets" Condition="Exists('..\packages\Microsoft.Web.WebView2.1.0.2739.15\build\Microsoft.Web.WebView2.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Microsoft.Web.WebView2.1.0.2478.35\build\Microsoft.Web.WebView2.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Web.WebView2.1.0.2478.35\build\Microsoft.Web.WebView2.targets'))" />
<Error Condition="!Exists('..\packages\Microsoft.Web.WebView2.1.0.2739.15\build\Microsoft.Web.WebView2.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Web.WebView2.1.0.2739.15\build\Microsoft.Web.WebView2.targets'))" />
</Target>
</Project>
51 changes: 35 additions & 16 deletions src/UpdateVersions/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,24 +77,18 @@ private bool UpdateWebView2Version(XDocument props)
{
var dir = Path.GetDirectoryName(this.ApplicationProjectFile);
var xmlnotepadProject = Path.Combine(dir, "..", "XmlNotepad", "XmlNotepad.csproj");
var doc = XDocument.Load(xmlnotepadProject);
var ns = doc.Root.Name.Namespace;
var prefix = "Microsoft.Web.WebView2.Core";
string version = null;
foreach (var e in doc.Descendants(ns + "Reference"))
string version = GetWebView2Version(xmlnotepadProject);
if (!string.IsNullOrEmpty(version))
{
string include = (string)e.Attribute("Include");
if (include.StartsWith(prefix))
var appVersion = GetWebView2Version(this.ApplicationProjectFile);
if (appVersion != null && appVersion != version)
{
var name = new AssemblyName(include);
version = name.Version.ToString();
break;
throw new Exception("WebView2 version is inconsistent in " + this.ApplicationProjectFile +
$". XmlNotepad has {version} while application has {appVersion}");
}
}
if (!string.IsNullOrEmpty(version))
{

WebView2Version = version;
ns = props.Root.Name.Namespace;
var ns = props.Root.Name.Namespace;
var wve = props.Root.Descendants(ns + "WebView2Version").FirstOrDefault();
if (wve != null)
{
Expand All @@ -117,6 +111,23 @@ private bool UpdateWebView2Version(XDocument props)
return false;
}

private string GetWebView2Version(string projectFile)
{
var doc = XDocument.Load(projectFile);
var ns = doc.Root.Name.Namespace;
var prefix = "Microsoft.Web.WebView2.Core";
foreach (var e in doc.Descendants(ns + "Reference"))
{
string include = (string)e.Attribute("Include");
if (include.StartsWith(prefix))
{
var name = new AssemblyName(include);
return name.Version.ToString();
}
}
return null;
}

private bool UpdateCSharpVersion(Version v)
{
// Fix these assembly attributes:
Expand Down Expand Up @@ -618,8 +629,16 @@ static int Main(string[] args)
sync.AppManifestFile = Path.Combine(solutionPath, "XmlNotepadPackage", "Package.appxmanifest");
sync.DropDir = Path.Combine(solutionPath, "drop");
sync.UpdatesFile = Path.Combine(solutionPath, "Updates", "Updates.xml");
bool rc = sync.Execute();
return rc ? 0 : 1;
try
{
bool rc = sync.Execute();
return rc ? 0 : 1;
}
catch (Exception ex)
{
sync.Log.LogError(ex.Message);
return 2;
}
}
}
}
4 changes: 0 additions & 4 deletions src/XmlNotepadSetup/Product.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,6 @@
<Component Id="Employee.htm" Guid="6da8da4a-e901-46cb-aea3-00526cd90e34">
<File Id="Employee.htm" KeyPath="yes" />
</Component>
<Component Id="rss.htm" Guid="891507ec-1d32-445d-bd70-856b980cfa96">
<File Id="rss.htm" KeyPath="yes" />
</Component>
</DirectoryRef>
<!-- shortcut in start menu -->
<DirectoryRef Id="ApplicationProgramsFolder">
Expand Down Expand Up @@ -174,7 +171,6 @@
<ComponentRef Id="rsspretty.xsl" />
<ComponentRef Id="willy.xsl" />
<ComponentRef Id="Employee.htm" />
<ComponentRef Id="rss.htm" />
<ComponentRef Id="ApplicationShortcut" />
</Feature>
<WixVariable Id="WixUILicenseRtf" Value="$(var.Application.TargetDir)\license.rtf" />
Expand Down

0 comments on commit b472fb3

Please sign in to comment.