Skip to content

Commit

Permalink
Merge pull request #48 from iCoreSolutions/bug/47
Browse files Browse the repository at this point in the history
Fix of temporary file handling and missing dll's in tests.
  • Loading branch information
brutaldev authored Aug 29, 2018
2 parents e6c3332 + 47572f5 commit e7eeac5
Show file tree
Hide file tree
Showing 13 changed files with 420 additions and 150 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ deploy/
[Bb]in/
[Oo]bj/

# Visual Studio 2015/2017 cache/options directory
.vs/

# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
Expand Down
14 changes: 14 additions & 0 deletions src/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# EditorConfig is awesome: https://EditorConfig.org

# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = crlf
insert_final_newline = true

[*.cs]
indent_size: 2
indent_style: space

Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,6 @@
<Compile Include="SignAssemblyTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Brutal.Dev.StrongNameSigner\Brutal.Dev.StrongNameSigner.csproj">
<Project>{947eecc6-5ebc-4d2a-bac4-8e88b5bafe84}</Project>
<Name>Brutal.Dev.StrongNameSigner</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
<None Include="TestAssemblies\PasswordTest.pfx">
Expand Down Expand Up @@ -153,9 +147,15 @@
<None Include="TestAssemblies\Brutal.Dev.StrongNameSigner.TestAssembly.A.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="TestAssemblies\Brutal.Dev.StrongNameSigner.TestAssembly.B.dll">
<None Include="TestAssemblies\Brutal.Dev.StrongNameSigner.TestAssembly.A.pdb">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="TestAssemblies\Brutal.Dev.StrongNameSigner.TestAssembly.B.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="TestAssemblies\Brutal.Dev.StrongNameSigner.TestAssembly.A.pdb">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<None Include="TestAssemblies\Brutal.Dev.StrongNameSigner.TestAssembly.A.Signed.dll">
Expand All @@ -165,6 +165,12 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Brutal.Dev.StrongNameSigner\Brutal.Dev.StrongNameSigner.csproj">
<Project>{947eecc6-5ebc-4d2a-bac4-8e88b5bafe84}</Project>
<Name>Brutal.Dev.StrongNameSigner</Name>
</ProjectReference>
</ItemGroup>
<Choose>
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
<ItemGroup>
Expand Down
95 changes: 94 additions & 1 deletion src/Brutal.Dev.StrongNameSigner.Tests/SignAssemblyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;
using System.Reflection;

namespace Brutal.Dev.StrongNameSigner.Tests
Expand All @@ -13,6 +12,7 @@ public class SignAssemblyTests
{
private static readonly string TestAssemblyDirectory = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"TestAssemblies");


[Test]
public void SignAssembly_Public_API_Test()
{
Expand Down Expand Up @@ -144,6 +144,99 @@ public void SignAssembly_Should_Reassemble_NET_40_x64_Assembly_Correctly()
info.Is64BitOnly.ShouldBe(true);
info.IsSigned.ShouldBe(true);
}


[Test]
public void SignAssembly_InPlaceWithPdb_Should_Succeed()
{
var tempDir = Path.Combine(TestAssemblyDirectory, Guid.NewGuid().ToString("N"));
Directory.CreateDirectory(tempDir);
try
{
string targetAssemblyPath = Path.Combine(tempDir, "Brutal.Dev.StrongNameSigner.TestAssembly.A.dll");
File.Copy(Path.Combine(TestAssemblyDirectory, "Brutal.Dev.StrongNameSigner.TestAssembly.A.dll"), targetAssemblyPath);
File.Copy(Path.Combine(TestAssemblyDirectory, "Brutal.Dev.StrongNameSigner.TestAssembly.A.pdb"), Path.Combine(tempDir, "Brutal.Dev.StrongNameSigner.TestAssembly.A.pdb"));

SigningHelper.SignAssembly(targetAssemblyPath);
var info = SigningHelper.GetAssemblyInfo(targetAssemblyPath);
Assert.IsTrue(info.IsSigned);
}
finally
{
Directory.Delete(tempDir, true);
}
}

[Test]
public void SignAssembly_NewLocationWithPdb_Should_Succeed()
{
var tempDir = Path.Combine(TestAssemblyDirectory, Guid.NewGuid().ToString("N"));
Directory.CreateDirectory(tempDir);
var outDir = Path.Combine(tempDir, "out");
Directory.CreateDirectory(outDir);
try
{
string sourceAssemblyPath = Path.Combine(tempDir, "Brutal.Dev.StrongNameSigner.TestAssembly.A.dll");
File.Copy(Path.Combine(TestAssemblyDirectory, "Brutal.Dev.StrongNameSigner.TestAssembly.A.dll"), sourceAssemblyPath);
File.Copy(Path.Combine(TestAssemblyDirectory, "Brutal.Dev.StrongNameSigner.TestAssembly.A.pdb"), Path.Combine(tempDir, "Brutal.Dev.StrongNameSigner.TestAssembly.A.pdb"));

SigningHelper.SignAssembly(sourceAssemblyPath, null, outDir);
string outAssembly = Path.Combine(outDir, Path.GetFileName(sourceAssemblyPath));
Assert.IsTrue(File.Exists(outAssembly));
Assert.IsTrue(File.Exists(Path.ChangeExtension(outAssembly, ".pdb")));
var info = SigningHelper.GetAssemblyInfo(outAssembly);
Assert.IsTrue(info.IsSigned);
}
finally
{
Directory.Delete(tempDir, true);
}
}

[Test]
public void SignAssembly_NewLocationWithoutPdb_Should_Succeed()
{
var tempDir = Path.Combine(TestAssemblyDirectory, Guid.NewGuid().ToString("N"));
Directory.CreateDirectory(tempDir);
var outDir = Path.Combine(tempDir, "out");
Directory.CreateDirectory(outDir);
try
{
string sourceAssemblyPath = Path.Combine(tempDir, "Brutal.Dev.StrongNameSigner.TestAssembly.A.dll");
File.Copy(Path.Combine(TestAssemblyDirectory, "Brutal.Dev.StrongNameSigner.TestAssembly.A.dll"), sourceAssemblyPath);

SigningHelper.SignAssembly(sourceAssemblyPath, null, outDir);
string outAssembly = Path.Combine(outDir, Path.GetFileName(sourceAssemblyPath));
Assert.IsTrue(File.Exists(outAssembly));
var info = SigningHelper.GetAssemblyInfo(outAssembly);
Assert.IsTrue(info.IsSigned);
}
finally
{
Directory.Delete(tempDir, true);
}
}

[Test]
public void SignAssembly_InPlaceWithoutPdb_Should_Succeed()
{
var tempDir = Path.Combine(TestAssemblyDirectory, Guid.NewGuid().ToString("N"));
Directory.CreateDirectory(tempDir);
try
{
string targetAssemblyPath = Path.Combine(tempDir, "Brutal.Dev.StrongNameSigner.TestAssembly.A.dll");
File.Copy(Path.Combine(TestAssemblyDirectory, "Brutal.Dev.StrongNameSigner.TestAssembly.A.dll"), targetAssemblyPath);

SigningHelper.SignAssembly(targetAssemblyPath);
var info = SigningHelper.GetAssemblyInfo(targetAssemblyPath);
Assert.IsTrue(info.IsSigned);

}
finally
{
Directory.Delete(tempDir, true);
}
}
}
}

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions src/Brutal.Dev.StrongNameSigner.sln
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Brutal.Dev.StrongNameSigner
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{239CD9FD-F026-419E-9C5D-4AAB4627A614}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
Brutal.Dev.StrongNameSigner.Setup\EULA.txt = Brutal.Dev.StrongNameSigner.Setup\EULA.txt
..\README.md = ..\README.md
Brutal.Dev.StrongNameSigner.Setup\StrongNameSigner.iss = Brutal.Dev.StrongNameSigner.Setup\StrongNameSigner.iss
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
<ItemGroup>
<Compile Include="AssemblyInfo.cs" />
<Compile Include="AutomaticBuildTask.cs" />
<Compile Include="ForceAssemblyReferenceAttribute.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SigningHelper.cs" />
</ItemGroup>
Expand Down
21 changes: 21 additions & 0 deletions src/Brutal.Dev.StrongNameSigner/ForceAssemblyReferenceAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Brutal.Dev.StrongNameSigner;
using System;
using System.Linq;

namespace Brutal.Dev.StrongNameSigner
{
/// <summary>
/// Attribute used to force an assembly reference to a specific assembly to be actually referenced and copied
/// locally.
/// See https://stackoverflow.com/questions/15816769/dependent-dll-is-not-getting-copied-to-the-build-output-folder-in-visual-studio
/// </summary>
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class ForceAssemblyReferenceAttribute : Attribute
{
public ForceAssemblyReferenceAttribute(Type forcedType)
{
Action<Type> noop = _ => { };
noop(forcedType);
}
}
}
12 changes: 11 additions & 1 deletion src/Brutal.Dev.StrongNameSigner/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Brutal.Dev.StrongNameSigner;
using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
Expand Down Expand Up @@ -36,3 +37,12 @@
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.2.0.0")]
[assembly: AssemblyFileVersion("2.2.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
// StrongNameSigner and copied along to the output directory as well as the UnitTests when running
// them, we use this "hack".
[assembly: ForceAssemblyReference(typeof(Mono.Cecil.Pdb.NativePdbReader))]
[assembly: ForceAssemblyReference(typeof(Mono.Cecil.Mdb.MdbReader))]
[assembly: ForceAssemblyReference(typeof(Mono.Cecil.Rocks.TypeDefinitionRocks))]
Loading

0 comments on commit e7eeac5

Please sign in to comment.