Skip to content

Commit

Permalink
Fix issues #38 and tested #44.
Browse files Browse the repository at this point in the history
Update version numbers.
Ignore delay signed assemblies that simply throw exception.
Fix password field not being disabled in the UI.
Update packages.
  • Loading branch information
brutaldev committed Nov 2, 2021
1 parent 33db44f commit 330a4ce
Show file tree
Hide file tree
Showing 13 changed files with 62 additions and 40 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ If you are making use of the [NuGet package](https://www.nuget.org/packages/Brut
```xml
<Target Name="BeforeBuild">
<Exec ContinueOnError="false"
Command="&quot;..\packages\Brutal.Dev.StrongNameSigner.2.8.0\build\StrongNameSigner.Console.exe&quot; -in &quot;..\packages&quot;" />
Command="&quot;..\packages\Brutal.Dev.StrongNameSigner.2.9.0\build\StrongNameSigner.Console.exe&quot; -in &quot;..\packages&quot;" />
</Target>
```

Expand All @@ -57,7 +57,7 @@ To add multiple directories to process at the same time (similar to how the UI c
```xml
<Target Name="BeforeBuild">
<Exec ContinueOnError="false"
Command="&quot;..\packages\Brutal.Dev.StrongNameSigner.2.8.0\build\StrongNameSigner.Console.exe&quot; -in &quot;..\packages\elmah.corelibrary.1.2.2|..\packages\Elmah.MVC.2.8.0&quot;" />
Command="&quot;..\packages\Brutal.Dev.StrongNameSigner.2.9.0\build\StrongNameSigner.Console.exe&quot; -in &quot;..\packages\elmah.corelibrary.1.2.2|..\packages\Elmah.MVC.2.9.0&quot;" />
</Target>
```

Expand All @@ -69,7 +69,7 @@ You can also use wildcards for each of your input directories. The above example
```xml
<Target Name="BeforeBuild">
<Exec ContinueOnError="false"
Command="&quot;..\packages\Brutal.Dev.StrongNameSigner.2.8.0\build\StrongNameSigner.Console.exe&quot; -in &quot;..\packages\elmah.*&quot;" />
Command="&quot;..\packages\Brutal.Dev.StrongNameSigner.2.9.0\build\StrongNameSigner.Console.exe&quot; -in &quot;..\packages\elmah.*&quot;" />
</Target>
```

Expand All @@ -78,7 +78,7 @@ Wildcards can also be complex and placed anywhere in the path. This is useful if
```xml
<Target Name="BeforeBuild">
<Exec ContinueOnError="false"
Command="&quot;..\packages\Brutal.Dev.StrongNameSigner.2.8.0\build\StrongNameSigner.Console.exe&quot; -in &quot;..\packages\Microsoft.*.Security*\*\net45&quot;" />
Command="&quot;..\packages\Brutal.Dev.StrongNameSigner.2.9.0\build\StrongNameSigner.Console.exe&quot; -in &quot;..\packages\Microsoft.*.Security*\*\net45&quot;" />
</Target>
```

Expand All @@ -104,7 +104,7 @@ For example, ServiceStack's PostgreSQL NuGet package is not signed but other dep
```xml
<Target Name="BeforeBuild">
<Exec ContinueOnError="false"
Command="&quot;..\packages\Brutal.Dev.StrongNameSigner.2.8.0\build\StrongNameSigner.Console.exe&quot; -in &quot;..\packages\ServiceStack.OrmLite.PostgreSQL.4.0.40\lib\net40|..\packages\ServiceStack.Text.Signed.4.0.40\lib\net40|..\packages\ServiceStack.OrmLite.Signed.4.0.40&quot;" />
Command="&quot;..\packages\Brutal.Dev.StrongNameSigner.2.9.0\build\StrongNameSigner.Console.exe&quot; -in &quot;..\packages\ServiceStack.OrmLite.PostgreSQL.4.0.40\lib\net40|..\packages\ServiceStack.Text.Signed.4.0.40\lib\net40|..\packages\ServiceStack.OrmLite.Signed.4.0.40&quot;" />
</Target>
```

Expand Down
6 changes: 5 additions & 1 deletion src/Brutal.Dev.StrongNameSigner.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,11 @@ private static AssemblyInfo SignSingleAssembly(string assemblyPath, string keyPa
var oldInfo = SigningHelper.GetAssemblyInfo(assemblyPath);
var newInfo = SigningHelper.SignAssembly(assemblyPath, keyPath, outputDirectory, password, probingPaths);

if (!oldInfo.IsSigned && newInfo.IsSigned)
if (newInfo.SigningType == StrongNameType.DelaySigned)
{
PrintMessage("Delay-signed assembly signing is not supported yet...", LogLevel.Verbose);
}
else if (!oldInfo.IsSigned && newInfo.IsSigned)
{
PrintMessageColor(string.Format("'{0}' was strong-name signed successfully.", newInfo.FilePath), LogLevel.Changes, ConsoleColor.Green);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.8.0.0")]
[assembly: AssemblyFileVersion("2.8.0.0")]
[assembly: AssemblyVersion("2.9.0.0")]
[assembly: AssemblyFileVersion("2.9.0.0")]
2 changes: 1 addition & 1 deletion src/Brutal.Dev.StrongNameSigner.Setup/StrongNameSigner.iss
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#define MyAppID "{A89C23E7-A764-4F59-8EF3-5AB0A33E5849}"
#define MyAppName ".NET Assembly Strong-Name Signer"
#define MyAppNameNoSpaces "StrongNameSigner"
#define MyAppVersion "2.8.0.0"
#define MyAppVersion "2.9.0.0"
#define MyAppPublisher "BrutalDev"
#define MyAppURL "https://github.com/brutaldev/StrongNameSigner"
#define MyAppExeName "StrongNameSigner.exe"
Expand Down
8 changes: 6 additions & 2 deletions src/Brutal.Dev.StrongNameSigner.Setup/StrongNameSigner.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata>
<id>Brutal.Dev.StrongNameSigner</id>
<version>2.8.0</version>
<version>2.9.0</version>
<title>.NET Assembly Strong-Name Signer</title>
<authors>Werner van Deventer</authors>
<owners>Werner van Deventer</owners>
Expand All @@ -21,7 +21,11 @@ The tool will also re-write the assembly references (as well as any InternalsVis
</description>
<summary>Automatic strong-name signing of referenced assemblies. Utility software to strong-name sign .NET assemblies, including assemblies you do not have the source code for.</summary>
<releaseNotes>- Update to the latest Mono Cecil which fixes a number of issues that can only make things better.
- Fix null reference error when signing ReferenceAssemblyAnnotator (issue #62).
- Fix issues #38 and tested #44.
- Update version numbers.
- Ignore delay signed assemblies that simply throw exception.
- Fix password field not being disabled in the UI.
- Update packages.
</releaseNotes>
<copyright>Werner van Deventer (https://brutaldev.com)</copyright>
<language>en-US</language>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\..\packages\NUnit3TestAdapter.4.0.0\build\net35\NUnit3TestAdapter.props" Condition="Exists('..\..\packages\NUnit3TestAdapter.4.0.0\build\net35\NUnit3TestAdapter.props')" />
<Import Project="..\..\packages\NUnit.3.13.2\build\NUnit.props" Condition="Exists('..\..\packages\NUnit.3.13.2\build\NUnit.props')" />
<Import Project="..\..\packages\Shouldly.4.0.3\build\Shouldly.props" Condition="Exists('..\..\packages\Shouldly.4.0.3\build\Shouldly.props')" />
<Import Project="..\..\packages\NUnit3TestAdapter.3.17.0\build\net35\NUnit3TestAdapter.props" Condition="Exists('..\..\packages\NUnit3TestAdapter.3.17.0\build\net35\NUnit3TestAdapter.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
Expand Down Expand Up @@ -55,6 +54,9 @@
<HintPath>..\..\packages\NUnit.3.13.2\lib\net40\nunit.framework.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Shouldly, Version=3.0.2.0, Culture=neutral, PublicKeyToken=6042cbcb05cbc941, processorArchitecture=MSIL">
<HintPath>..\..\packages\Shouldly.3.0.2\lib\net40\Shouldly.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
Expand Down Expand Up @@ -197,12 +199,9 @@
<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\NUnit3TestAdapter.3.17.0\build\net35\NUnit3TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\NUnit3TestAdapter.3.17.0\build\net35\NUnit3TestAdapter.props'))" />
<Error Condition="!Exists('..\..\packages\Shouldly.4.0.0\build\Shouldly.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Shouldly.4.0.0\build\Shouldly.targets'))" />
<Error Condition="!Exists('..\..\packages\Shouldly.4.0.3\build\Shouldly.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Shouldly.4.0.3\build\Shouldly.props'))" />
<Error Condition="!Exists('..\..\packages\NUnit.3.13.2\build\NUnit.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\NUnit.3.13.2\build\NUnit.props'))" />
<Error Condition="!Exists('..\..\packages\NUnit3TestAdapter.4.0.0\build\net35\NUnit3TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\NUnit3TestAdapter.4.0.0\build\net35\NUnit3TestAdapter.props'))" />
</Target>
<Import Project="..\..\packages\Shouldly.4.0.0\build\Shouldly.targets" Condition="Exists('..\..\packages\Shouldly.4.0.0\build\Shouldly.targets')" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
4 changes: 2 additions & 2 deletions src/Brutal.Dev.StrongNameSigner.Tests/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NUnit" version="3.13.2" targetFramework="net40" />
<package id="NUnit3TestAdapter" version="3.17.0" targetFramework="net40" />
<package id="Shouldly" version="4.0.3" targetFramework="net40" />
<package id="NUnit3TestAdapter" version="4.0.0" targetFramework="net40" />
<package id="Shouldly" version="3.0.2" targetFramework="net40" />
</packages>
9 changes: 7 additions & 2 deletions src/Brutal.Dev.StrongNameSigner.UI/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -380,11 +380,15 @@ private void BackgroundWorkerDoWork(object sender, DoWorkEventArgs e)
assemblyPair.OldInfo = SigningHelper.GetAssemblyInfo(filePath);
assemblyPair.NewInfo = SigningHelper.SignAssembly(filePath, keyFile, outputPath, password, probingPaths);

if (!assemblyPair.OldInfo.IsSigned && assemblyPair.NewInfo.IsSigned)
if (assemblyPair.NewInfo.SigningType == StrongNameType.DelaySigned)
{
log.Append("Delay-signed assembly signing is not supported yet...").AppendLine();
}
else if (!assemblyPair.OldInfo.IsSigned && assemblyPair.NewInfo.IsSigned)
{
log.Append("Strong-name signed successfully.").AppendLine();
signedAssemblyPaths.Add(assemblyPair.NewInfo.FilePath);
signedFiles++;
signedFiles++;
}
else
{
Expand Down Expand Up @@ -517,6 +521,7 @@ private void EnableControls(bool enabled)
buttonCancel.Enabled = !enabled;

textBoxKey.Enabled = enabled;
textBoxPassword.Enabled = enabled;
textBoxOutput.Enabled = enabled;
listViewAssemblies.Enabled = enabled;
buttonKey.Enabled = enabled;
Expand Down
4 changes: 2 additions & 2 deletions src/Brutal.Dev.StrongNameSigner.UI/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.8.0.0")]
[assembly: AssemblyFileVersion("2.8.0.0")]
[assembly: AssemblyVersion("2.9.0.0")]
[assembly: AssemblyFileVersion("2.9.0.0")]
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,17 @@
<ItemGroup>
<Reference Include="Microsoft.Build.Framework" />
<Reference Include="Microsoft.Build.Utilities.v4.0" />
<Reference Include="Mono.Cecil, Version=0.11.3.0, Culture=neutral, PublicKeyToken=50cebf1cceb9d05e, processorArchitecture=MSIL">
<HintPath>..\..\packages\Mono.Cecil.0.11.3\lib\net40\Mono.Cecil.dll</HintPath>
<Reference Include="Mono.Cecil, Version=0.11.4.0, Culture=neutral, PublicKeyToken=50cebf1cceb9d05e, processorArchitecture=MSIL">
<HintPath>..\..\packages\Mono.Cecil.0.11.4\lib\net40\Mono.Cecil.dll</HintPath>
</Reference>
<Reference Include="Mono.Cecil.Mdb, Version=0.11.3.0, Culture=neutral, PublicKeyToken=50cebf1cceb9d05e, processorArchitecture=MSIL">
<HintPath>..\..\packages\Mono.Cecil.0.11.3\lib\net40\Mono.Cecil.Mdb.dll</HintPath>
<Reference Include="Mono.Cecil.Mdb, Version=0.11.4.0, Culture=neutral, PublicKeyToken=50cebf1cceb9d05e, processorArchitecture=MSIL">
<HintPath>..\..\packages\Mono.Cecil.0.11.4\lib\net40\Mono.Cecil.Mdb.dll</HintPath>
</Reference>
<Reference Include="Mono.Cecil.Pdb, Version=0.11.3.0, Culture=neutral, PublicKeyToken=50cebf1cceb9d05e, processorArchitecture=MSIL">
<HintPath>..\..\packages\Mono.Cecil.0.11.3\lib\net40\Mono.Cecil.Pdb.dll</HintPath>
<Reference Include="Mono.Cecil.Pdb, Version=0.11.4.0, Culture=neutral, PublicKeyToken=50cebf1cceb9d05e, processorArchitecture=MSIL">
<HintPath>..\..\packages\Mono.Cecil.0.11.4\lib\net40\Mono.Cecil.Pdb.dll</HintPath>
</Reference>
<Reference Include="Mono.Cecil.Rocks, Version=0.11.3.0, Culture=neutral, PublicKeyToken=50cebf1cceb9d05e, processorArchitecture=MSIL">
<HintPath>..\..\packages\Mono.Cecil.0.11.3\lib\net40\Mono.Cecil.Rocks.dll</HintPath>
<Reference Include="Mono.Cecil.Rocks, Version=0.11.4.0, Culture=neutral, PublicKeyToken=50cebf1cceb9d05e, processorArchitecture=MSIL">
<HintPath>..\..\packages\Mono.Cecil.0.11.4\lib\net40\Mono.Cecil.Rocks.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand Down Expand Up @@ -101,4 +101,4 @@
</PropertyGroup>
<Error Condition="!Exists('..\..\packages\StyleCop.MSBuild.6.2.0\build\StyleCop.MSBuild.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\StyleCop.MSBuild.6.2.0\build\StyleCop.MSBuild.targets'))" />
</Target>
</Project>
</Project>
4 changes: 2 additions & 2 deletions src/Brutal.Dev.StrongNameSigner/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.8.0.0")]
[assembly: AssemblyFileVersion("2.8.0.0")]
[assembly: AssemblyVersion("2.9.0.0")]
[assembly: AssemblyFileVersion("2.9.0.0")]

// These assemblies are used by Cecil, and reading assemblies with symbols without these DLL's present
// will cause an error ("No Symbols Found"). So to ensure that these are actually referenced by
Expand Down
20 changes: 15 additions & 5 deletions src/Brutal.Dev.StrongNameSigner/SigningHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ public static AssemblyInfo SignAssembly(string assemblyPath, string keyPath, str
var info = GetAssemblyInfo(assemblyPath);

// Don't sign assemblies with a strong-name signature.
if (info.IsSigned)
// Also do not sign delay signed assemblies, need to figure out how to do this correctly: https://github.com/brutaldev/StrongNameSigner/issues/42
if (info.IsSigned || info.SigningType == StrongNameType.DelaySigned)
{
// If the target directory is different from the input...
if (!outputFileMgr.IsInPlaceReplace)
Expand Down Expand Up @@ -296,7 +297,10 @@ public static bool FixAssemblyReference(string assemblyPath, string referenceAss
assemblyReference.PublicKeyToken = b.Name.PublicKeyToken ?? new byte[0];
assemblyReference.Version = b.Name.Version;

a.Write(fileManagerA.IntermediateAssemblyPath, new WriterParameters { StrongNameKeyPair = GetStrongNameKeyPair(keyPath, keyFilePassword), WriteSymbols = File.Exists(Path.ChangeExtension(assemblyPath, ".pdb")) });
if (!a.Name.IsRetargetable)
{
a.Write(fileManagerA.IntermediateAssemblyPath, new WriterParameters { StrongNameKeyPair = GetStrongNameKeyPair(keyPath, keyFilePassword), WriteSymbols = File.Exists(Path.ChangeExtension(assemblyPath, ".pdb")) });
}

AssemblyInfoCache.TryRemove(assemblyPath, out var _);

Expand All @@ -313,8 +317,11 @@ public static bool FixAssemblyReference(string assemblyPath, string referenceAss
friendReference.ConstructorArguments.Clear();
friendReference.ConstructorArguments.Add(new CustomAttributeArgument(typeRef, a.Name.Name + ", PublicKey=" + BitConverter.ToString(a.Name.PublicKey).Replace("-", string.Empty)));

// Save and resign.
b.Write(fileManagerB.IntermediateAssemblyPath, new WriterParameters { StrongNameKeyPair = GetStrongNameKeyPair(keyPath, keyFilePassword), WriteSymbols = File.Exists(Path.ChangeExtension(referenceAssemblyPath, ".pdb")) });
if (!b.Name.IsRetargetable)
{
// Save and resign.
b.Write(fileManagerB.IntermediateAssemblyPath, new WriterParameters { StrongNameKeyPair = GetStrongNameKeyPair(keyPath, keyFilePassword), WriteSymbols = File.Exists(Path.ChangeExtension(referenceAssemblyPath, ".pdb")) });
}

AssemblyInfoCache.TryRemove(assemblyPath, out var _);

Expand Down Expand Up @@ -390,7 +397,10 @@ public static bool RemoveInvalidFriendAssemblies(string assemblyPath, string key

if (fixApplied)
{
a.Write(outFileMgr.IntermediateAssemblyPath, new WriterParameters { StrongNameKeyPair = GetStrongNameKeyPair(keyPath, keyFilePassword), WriteSymbols = File.Exists(Path.ChangeExtension(assemblyPath, ".pdb")) });
if (!a.Name.IsRetargetable)
{
a.Write(outFileMgr.IntermediateAssemblyPath, new WriterParameters { StrongNameKeyPair = GetStrongNameKeyPair(keyPath, keyFilePassword), WriteSymbols = File.Exists(Path.ChangeExtension(assemblyPath, ".pdb")) });
}

AssemblyInfoCache.TryRemove(assemblyPath, out var _);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Brutal.Dev.StrongNameSigner/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Mono.Cecil" version="0.11.3" targetFramework="net40" />
<package id="Mono.Cecil" version="0.11.4" targetFramework="net40" />
<package id="StyleCop.MSBuild" version="6.2.0" targetFramework="net40" developmentDependency="true" />
</packages>

0 comments on commit 330a4ce

Please sign in to comment.