Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dsplaisted/strongnamer
https://github.com/dsplaisted/strongnamer
Last synced: 18 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/dsplaisted/strongnamer
- Owner: dsplaisted
- License: mit
- Created: 2015-10-25T20:26:23.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2024-02-27T13:34:34.000Z (3 months ago)
- Last Synced: 2024-04-27T12:59:46.969Z (26 days ago)
- Language: C#
- Size: 111 KB
- Stars: 324
- Watchers: 20
- Forks: 52
- Open Issues: 40
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Lists
- awesome-dotnet - Strong Namer - Automatically add strong names to referenced assemblies which do not already have a strong name. This will allow you to reference and use (NuGet packages with) assemblies which are not strong named from your projects that do use a strong name. (Strong Naming)
- awsome-dotnet - Strong Namer - Automatically add strong names to referenced assemblies which do not already have a strong name. This will allow you to reference and use (NuGet packages with) assemblies which are not strong named from your projects that do use a strong name. (Strong Naming)
- awesome-dot-dev - Strong Namer - Automatically add strong names to referenced assemblies which do not already have a strong name. This will allow you to reference and use (NuGet packages with) assemblies which are not strong named from your projects that do use a strong name. (Strong Naming)
- awesome-dotnet - Strong Namer - Automatically add strong names to referenced assemblies which do not already have a strong name. This will allow you to reference and use (NuGet packages with) assemblies which are not strong named from your projects that do use a strong name. (Strong Naming)
- awesome-dotnet - Strong Namer - Automatically add strong names to referenced assemblies which do not already have a strong name. This will allow you to reference and use (NuGet packages with) assemblies which are not strong named from your projects that do use a strong name. (Strong Naming)
- awesome-csharp - Strong Namer - Automatically add strong names to referenced assemblies which do not already have a strong name. This will allow you to reference and use (NuGet packages with) assemblies which are not strong named from your projects that do use a strong name. (Strong Naming)
- awesome-dotnet-cn - Strong Namer - 自动添加强命名到引用的那些没有强命名的程序集,这样就可以使用强命名在项目中引用和使用没有强命名的程序集(以及NuGet包)。 (强命名)
README
# Strong Namer
Most applications in .NET [do not need to be strong named][1]. Strong names can
also introduce pain because they end up requiring binding redirects. Because of
this, many OSS libraries do not strong name their assemblies.[1]: https://github.com/dotnet/corefx/blob/c02d33b18398199f6acc17d375dab154e9a1df66/Documentation/project-docs/strong-name-signing.md#faq
Strong named assemblies that reference assemblies that aren't strong named are
rejected by the .NET Framework (desktop app only restriction).
So if for whatever reason you actually do need to strong name your project, you
couldn't easily consume open source packages.Strong Namer is a NuGet package which aims to change this. Simply install the
[StrongNamer](https://www.nuget.org/packages/strongnamer) NuGet package, and
it will transparently and automatically sign the assemblies you reference as
part of the build process.# Demo
Here's how to try Strong Namer out for yourself:
- Create a new Console application
- Add a strong name to the application
- *Go to the Signing tab of the project properties*
- *Check "Sign the assembly"*
- *In the key file dropdown, choose <New...>*
- *Choose a key file name (ie "key.snk"), uncheck the password option,
and click OK*
- Add a reference to the [Octokit](https://www.nuget.org/packages/octokit)
NuGet package
- Replace Program class with the following code:``` C#
using Octokit;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;class Program
{
static void Main(string[] args)
{
MainAsyncWithErrorHandling().Wait();
}static async Task MainAsyncWithErrorHandling()
{
try
{
await MainAsync();
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}static async Task MainAsync()
{
var github = new GitHubClient(new ProductHeaderValue("MyAmazingApp"));
var user = await github.User.Get("half-ogre");
Console.WriteLine(user.Followers + " folks love the half ogre!");
}
}
```
- Start without debugging (CTRL+F5)![System.IO.FileLoadException: Could not load file or assembly 'Octokit, Version=0.16.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. A strongly-named assembly is required. (Exception from HRESULT: 0x80131044)
File name: 'Octokit, Version=0.16.0.0, Culture=neutral, PublicKeyToken=null'
at Program.MainAsync()
at Program.d__1.MoveNext() in C:\Users\daplaist\Documents\Visual Studio 2015\Projects\ConsoleApplication13\ConsoleApplication13\Program.cs:line 19](images/StrongNameSadPanda.png)
- :disappointed:
- Add a reference to the [StrongNamer](https://www.nuget.org/packages/strongnamer)
NuGet package
- Start without debugging (CTRL+F5)![75 folks love the half ogre!](images/StrongNameSuccessSparkles.png)
- :sparkles: :fireworks: :smile: :fireworks: :sparkles:# How does it work?
The NuGet package includes an MSBuild targets file and task which hook into the
build process and add a strong name to any references which aren't strong named
just before they are passed to the compiler.The task uses Mono.Cecil to do this. Credit goes to [Nivot.StrongNaming](https://github.com/oising/strongnaming) for showing me how
to do this.# Options
You can conditionally disable automated signing of unsigned packages by setting the "DisableStrongNamer" property to "true". This is particularly useful if you have a custom build configuration for your application (e.g., you only wish for unsigned packages to be autosigned in specific environments).