Skip to content

Commit

Permalink
Implemented correct illinker cleaning / Version fix
Browse files Browse the repository at this point in the history
  • Loading branch information
stavroskasidis committed Feb 8, 2022
1 parent d1029df commit 6a55d00
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 32 deletions.
18 changes: 6 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,10 @@ dotnet add package BlazorWasmAntivirusProtection

2. Publish your app in Release mode and test it!
```
#Perform a clean first, see "Known Issue" below
dotnet clean BlazorHostedSampleApp.sln -c Release
dotnet publish Server\BlazorHostedSampleApp.Server.csproj -c Release
```
*Nuget package page can be found [here](https://www.nuget.org/packages/BlazorDialog).*

## ⚠️ Known issue ⚠️
If you try to publish a project after you have already published you have to clean your solution or the publish will fail with the following exception:

`error MSB4018: The "PInvokeTableGenerator" task failed unexpectedly.`

This happens because the il linker cannot load the existing modified dlls in the obj folder.
To prevent this error you should perform a clean on your solution before every publish, as displayed above.

## Configuration
The following options allow you to customize the tasks executed by this package.
### **Custom dll rename extension**
Expand Down Expand Up @@ -73,7 +62,12 @@ This work was inspired by the post in https://github.com/dotnet/aspnetcore/issue

## Release Notes

<details open="open"><summary>1.0</summary>
<details open="open"><summary>1.2</summary>

>- Fixed sequential publishing issue.
</details>
<details><summary>1.0</summary>

>- Added customization options.
</details>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="6.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="6.0.1" PrivateAssets="all" />
<PackageReference Include="BlazorWasmAntivirusProtection" Version="1.7.0" />
<PackageReference Include="BlazorWasmAntivirusProtection" Version="1.2.0-beta" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="6.0.1" />
<PackageReference Include="BlazorWasmAntivirusProtection" Version="1.7.0" />
<PackageReference Include="BlazorWasmAntivirusProtection" Version="1.2.0-beta" />
</ItemGroup>

<ItemGroup>
Expand Down
17 changes: 8 additions & 9 deletions src/BlazorWasmAntivirusProtection.Tasks/CleanOldDlls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace BlazorWasmAntivirusProtection.Tasks
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Net.Http;
using System.Text;

Expand All @@ -15,20 +16,18 @@ public class CleanOldDlls : Task

public override bool Execute()
{
Debugger.Launch();
if (!Directory.Exists(IntermediateLinkDir)) return true;

Log.LogMessage(MessageImportance.High, $"BlazorWasmAntivirusProtection: Cleaning old .dll files");

foreach(var file in Directory.GetFiles(IntermediateLinkDir, "*.dll"))
var linkSemaphore = Path.Combine(IntermediateLinkDir, "Link.semaphore");
var existingDll = Directory.GetFiles(IntermediateLinkDir, "*.dll").FirstOrDefault();
if (File.Exists(linkSemaphore) && existingDll != null && IsDllHeaderBz(existingDll))
{
if (IsDllHeaderBz(file))
{
File.Delete(file);
}
Log.LogMessage(MessageImportance.High, $"BlazorWasmAntivirusProtection: Cleaning old .dll files");
//We delete the Link.semaphore file to force a regeneration of objs in the IntermediateLinkDir
//This is to remove remnants of a previous publish
File.Delete(linkSemaphore);
}


return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<PackageProjectUrl>https://github.com/stavroskasidis/BlazorWasmAntivirusProtection</PackageProjectUrl>
<Description>This package attempts to guard against false positives from antiviruses that flag Blazor Wasm as malware</Description>
<VersionSuffix>$(VersionSuffix)</VersionSuffix>
<Version>1.7.0</Version>
<Version>1.2.0</Version>
<Version Condition=" '$(VersionSuffix)' != '' ">$(Version)-$(VersionSuffix)</Version>
</PropertyGroup>

Expand All @@ -25,11 +25,7 @@
<Output TaskParameter="TargetOutputs" ItemName="_TasksProjectOutputs" />
</MSBuild>
<ItemGroup>
<Content Include="@(_TasksProjectOutputs)" Condition="('$(Configuration)' == 'Release' And '%(_TasksProjectOutputs.Extension)' == '.dll') Or
'$(Configuration)' == 'Debug' And ('%(_TasksProjectOutputs.Extension)' == '.dll' Or '%(_TasksProjectOutputs.Extension)' == '.pdb')"
Pack="true"
PackagePath="tasks\%(_TasksProjectOutputs.TargetPath)"
KeepMetadata="Pack;PackagePath" />
<Content Include="@(_TasksProjectOutputs)" Condition="('$(Configuration)' == 'Release' And '%(_TasksProjectOutputs.Extension)' == '.dll') Or &#xD;&#xA; '$(Configuration)' == 'Debug' And ('%(_TasksProjectOutputs.Extension)' == '.dll' Or '%(_TasksProjectOutputs.Extension)' == '.pdb')" Pack="true" PackagePath="tasks\%(_TasksProjectOutputs.TargetPath)" KeepMetadata="Pack;PackagePath" />
</ItemGroup>
</Target>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@

<PropertyGroup>
<ComputeBlazorExtensionsDependsOn>$(ComputeBlazorExtensionsDependsOn);_ChangeDllHeaders</ComputeBlazorExtensionsDependsOn>
<WasmNestedPublishAppDependsOn>_CleanOldDlls;$(WasmNestedPublishAppDependsOn)</WasmNestedPublishAppDependsOn>

</PropertyGroup>

<Target Name="_CleanOldDlls">
<Target Name="_CleanOldDlls" BeforeTargets="PrepareForILLink">
<CleanOldDlls IntermediateLinkDir="$(IntermediateLinkDir)"></CleanOldDlls>
</Target>

Expand Down

0 comments on commit 6a55d00

Please sign in to comment.