clowd / Clowd.Squirrel

Quick and easy installer and automatic updates for cross-platform dotnet applications
427 stars 39 forks source link

.NET Framework support? #180

Closed RichardD2 closed 12 months ago

RichardD2 commented 12 months ago

I am migrating from Squirrel.Windows to support signing with the AzureSignTool. My application targets .NET Framework 4.7.2, and I am referencing Clowd.Squirrel v2.9.42, which is the latest non-preview version on NuGet.

No matter what I do, releasify returns an error.

Skipping the --framework argument, or passing --framework=net472 returns:

[ERRO] System.InvalidOperationException: The input package file ... targets multiple platforms - .NETFramework4.7.2; net472; - and cannot be transformed into a release package.

Passing --framework=.NETFramework4.7.2 returns:

[ERRO] System.Exception: Runtime '.NETFramework4.7.2' is unsupported. Specify a dotnet runtime (eg. 'net6.0') or a static runtime such as: net45, net451, net452, net46, net461, net462, net47, net471, net472, net48, netcoreapp3.1-x86, netcoreapp3.1-x64, net5-x86, net5-x64, net6.0.2-x86, net6.0.2-x64, vcredist100-x86, vcredist100-x64, vcredist110-x86, vcredist110-x64, vcredist120-x86, vcredist120-x64, vcredist140-x86, vcredist140-x64, vcredist141-x86, vcredist141-x64, vcredist142-x86, vcredist142-x64, vcredist143-x86, vcredist143-x64

My .nuspec file originally had:

<dependencies>
    <group targetFramework=".NETFramework4.7.2" />
</dependencies>

I have tried changing it to:

<dependencies>
    <group targetFramework="net472" />
</dependencies>

which made no difference. NuGet Package Explorer still shows that the .nupkg file has a single target framework:

image

Have I missed something obvious, or does this project not actually support .NET Framework applications?

RichardD2 commented 12 months ago

Some progress: I changed the output path in the .nupkg file from lib\net472\ to lib\, and now I get a different error:

[ERRO] System.InvalidOperationException: The input package file ... must have no dependencies. at Squirrel.ReleasePackage.CreateReleasePackage(...) in ./Internal/ReleasePackage.cs:line 92

Surely that doesn't mean we can't distribute applications with any dependencies, as the error message suggests.

I must be missing something here.

RichardD2 commented 12 months ago

I've removed the target framework group:

<dependencies>
    <group targetFramework="..." />
</dependencies>

NuGet Package Explorer now shows "no dependencies":

image

It contains a single lib folder:

image

And now I get:

[ERRO] System.InvalidOperationException: Invalid package: One 'lib' folder expected. None was found.

remco1271 commented 12 months ago

See readme.md you can use the Squirrel pack --packId... command then you don't need a .nuspec file

RichardD2 commented 12 months ago

@remco1271 Thanks; that pointed me in the right direction.

I was trying to minimize the changes, so replacing nuget pack + releasify with just pack was a step too far.

Looking at the .nuspec file generated by the pack command, it seems the files need to be in a lib\native folder within the package, rather than lib\net472 or just lib.

With that in place, I've finally managed to build a new release. 😁 Now I just need to check that the old Squirrel.Windows app can update from this new release.

For ref, my final files were:

Project.nuspec:

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
    <metadata>
        <id>Package-Id</id>
        <version>0.0.0.0</version>
        <authors>Company Name</authors>
        <requireLicenseAcceptance>false</requireLicenseAcceptance>
        <icon>Icon.png</icon>
        <projectUrl>website</projectUrl>
        <description>description</description>
        <copyright>Copyright © Company Name</copyright>
        <language>en-GB</language>
    </metadata>
    <files>
        <file src="*.*" target="lib\native\" exclude="*.nupkg;*.vshost.*;*.xml;*.dll.config"/>
        <file src="..\..\..\..\..\Icon.png" target="Icon.png" />
    </files>
</package>

Project.csproj:

<Target Name="SquirrelReleasify" AfterTargets="PostBuildEvent" Condition="'$(Configuration)' == 'Release'">
    <GetAssemblyIdentity AssemblyFiles="$(TargetPath)">
        <Output TaskParameter="Assemblies" ItemName="myAssemblyInfo" />
    </GetAssemblyIdentity>

    <PropertyGroup>
        <NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">$(USERPROFILE)\.nuget\packages\</NuGetPackageRoot>
    </PropertyGroup>

    <ItemGroup>
        <SquirrelExe Include="$(NuGetPackageRoot)\Clowd.Squirrel\2.9.42\tools\squirrel.exe" />
        <AzureSignToolExe Include="$(USERPROFILE)\.dotnet\tools\azuresigntool.exe" />
    </ItemGroup>

    <Error Condition="!Exists(%(SquirrelExe.FullPath))" Text="You are trying to use the Clowd.Squirrel package, but it is not installed. Please install Clowd.Squirrel from the Package Manager. [%(SquirrelExe.FullPath)]" />

    <Error Condition="!Exists(%(AzureSignToolExe.FullPath))" Text="You are trying to use the AzureSignTool, but it is not installed. Please run &quot;dotnet tool install --global azuresigntool&quot; to install it. [%(AzureSignToolExe.FullPath)]" />

    <PropertyGroup>
        <ReleaseDir>$(ProjectDir)Releases</ReleaseDir>
        <SquirrelParams>--framework=net472 --signTemplate "%(AzureSignToolExe.FullPath) sign -s -kvu https://my-kv.vault.azure.net/ -kvc MyCert -kvm -fd sha384 -tr http://timestamp.digicert.com -td sha384 {{file}}"</SquirrelParams>
        <SemVerNumber>$([System.Version]::Parse(%(myAssemblyInfo.Version)).ToString(3))</SemVerNumber>
        <SourcePackage>$(ProjectDir)bin\$(Configuration)\Package-Id.$(SemVerNumber).nupkg</SourcePackage>
    </PropertyGroup>

    <Exec Command="nuget pack Package-Id.nuspec -Version %(myAssemblyInfo.Version) -Properties Configuration=$(Configuration) -OutputDirectory $(ProjectDir)bin\$(Configuration)\ -BasePath $(OutDir)" />

    <Error Condition="!Exists($(SourcePackage))" Text="The source package $(SourcePackage) does not exist." />

    <Exec Command="&quot;%(SquirrelExe.FullPath)&quot; releasify --package=&quot;$(SourcePackage)&quot; --releaseDir=&quot;$(ReleaseDir)&quot; $(SquirrelParams)" />
</Target>
RichardD2 commented 12 months ago

The update works! 🥳🎉