├── .gitattributes ├── .gitignore ├── LICENSE ├── README.md ├── StrongNamer.sln ├── azure-pipelines.yml ├── images ├── StrongNameSadPanda.png └── StrongNameSuccessSparkles.png ├── src ├── StrongNamer │ ├── AddStrongName.cs │ ├── CryptoConvert.cs │ ├── SharedKey.snk │ ├── StrongNamer.csproj │ ├── StrongNamer.targets │ └── StrongNamerAssemblyResolver.cs ├── TestConsoleApp │ ├── App.config │ ├── Program.cs │ └── TestConsoleApp.csproj └── TestLibrary │ ├── Class1.cs │ ├── SharedKey.snk │ └── TestLibrary.csproj └── version.json /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | #build/ 21 | bld/ 22 | [Bb]in/ 23 | [Oo]bj/ 24 | 25 | # Visual Studo 2015 cache/options directory 26 | .vs/ 27 | 28 | # MSTest test Results 29 | [Tt]est[Rr]esult*/ 30 | [Bb]uild[Ll]og.* 31 | 32 | # NUNIT 33 | *.VisualState.xml 34 | TestResult.xml 35 | 36 | # Build Results of an ATL Project 37 | [Dd]ebugPS/ 38 | [Rr]eleasePS/ 39 | dlldata.c 40 | 41 | *_i.c 42 | *_p.c 43 | *_i.h 44 | *.ilk 45 | *.meta 46 | *.obj 47 | *.pch 48 | *.pdb 49 | *.pgc 50 | *.pgd 51 | *.rsp 52 | *.sbr 53 | *.tlb 54 | *.tli 55 | *.tlh 56 | *.tmp 57 | *.tmp_proj 58 | *.log 59 | *.vspscc 60 | *.vssscc 61 | .builds 62 | *.pidb 63 | *.svclog 64 | *.scc 65 | 66 | # Chutzpah Test files 67 | _Chutzpah* 68 | 69 | # Visual C++ cache files 70 | ipch/ 71 | *.aps 72 | *.ncb 73 | *.opensdf 74 | *.sdf 75 | *.cachefile 76 | 77 | # Visual Studio profiler 78 | *.psess 79 | *.vsp 80 | *.vspx 81 | 82 | # TFS 2012 Local Workspace 83 | $tf/ 84 | 85 | # Guidance Automation Toolkit 86 | *.gpState 87 | 88 | # ReSharper is a .NET coding add-in 89 | _ReSharper*/ 90 | *.[Rr]e[Ss]harper 91 | *.DotSettings.user 92 | 93 | # JustCode is a .NET coding addin-in 94 | .JustCode 95 | 96 | # TeamCity is a build add-in 97 | _TeamCity* 98 | 99 | # DotCover is a Code Coverage Tool 100 | *.dotCover 101 | 102 | # NCrunch 103 | _NCrunch_* 104 | .*crunch*.local.xml 105 | 106 | # MightyMoose 107 | *.mm.* 108 | AutoTest.Net/ 109 | 110 | # Web workbench (sass) 111 | .sass-cache/ 112 | 113 | # Installshield output folder 114 | [Ee]xpress/ 115 | 116 | # DocProject is a documentation generator add-in 117 | DocProject/buildhelp/ 118 | DocProject/Help/*.HxT 119 | DocProject/Help/*.HxC 120 | DocProject/Help/*.hhc 121 | DocProject/Help/*.hhk 122 | DocProject/Help/*.hhp 123 | DocProject/Help/Html2 124 | DocProject/Help/html 125 | 126 | # Click-Once directory 127 | publish/ 128 | 129 | # Publish Web Output 130 | *.[Pp]ublish.xml 131 | *.azurePubxml 132 | # TODO: Comment the next line if you want to checkin your web deploy settings 133 | # but database connection strings (with potential passwords) will be unencrypted 134 | *.pubxml 135 | *.publishproj 136 | 137 | # NuGet Packages 138 | *.nupkg 139 | # The packages folder can be ignored because of Package Restore 140 | **/packages/* 141 | # except build/, which is used as an MSBuild target. 142 | !**/packages/build/ 143 | # Uncomment if necessary however generally it will be regenerated when needed 144 | #!**/packages/repositories.config 145 | 146 | # Windows Azure Build Output 147 | csx/ 148 | *.build.csdef 149 | 150 | # Windows Store app package directory 151 | AppPackages/ 152 | 153 | # Others 154 | *.[Cc]ache 155 | ClientBin/ 156 | [Ss]tyle[Cc]op.* 157 | ~$* 158 | *~ 159 | *.dbmdl 160 | *.dbproj.schemaview 161 | *.pfx 162 | *.publishsettings 163 | node_modules/ 164 | bower_components/ 165 | 166 | # RIA/Silverlight projects 167 | Generated_Code/ 168 | 169 | # Backup & report files from converting an old project file 170 | # to a newer Visual Studio version. Backup files are not needed, 171 | # because we have git ;-) 172 | _UpgradeReport_Files/ 173 | Backup*/ 174 | UpgradeLog*.XML 175 | UpgradeLog*.htm 176 | 177 | # SQL Server files 178 | *.mdf 179 | *.ldf 180 | 181 | # Business Intelligence projects 182 | *.rdl.data 183 | *.bim.layout 184 | *.bim_*.settings 185 | 186 | # Microsoft Fakes 187 | FakesAssemblies/ 188 | 189 | # Node.js Tools for Visual Studio 190 | .ntvs_analysis.dat 191 | 192 | # Visual Studio 6 build log 193 | *.plg 194 | 195 | # Visual Studio 6 workspace options file 196 | *.opt 197 | 198 | # NuGet lock file 199 | project.lock.json 200 | .nuget/NuGet.exe 201 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Daniel Plaisted 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Strong Namer 2 | 3 | Most applications in .NET [do not need to be strong named][1]. Strong names can 4 | also introduce pain because they end up requiring binding redirects. Because of 5 | this, many OSS libraries do not strong name their assemblies. 6 | 7 | [1]: https://github.com/dotnet/corefx/blob/c02d33b18398199f6acc17d375dab154e9a1df66/Documentation/project-docs/strong-name-signing.md#faq 8 | 9 | Strong named assemblies that reference assemblies that aren't strong named are 10 | rejected by the .NET Framework (desktop app only restriction). 11 | So if for whatever reason you actually do need to strong name your project, you 12 | couldn't easily consume open source packages. 13 | 14 | Strong Namer is a NuGet package which aims to change this. Simply install the 15 | [StrongNamer](https://www.nuget.org/packages/strongnamer) NuGet package, and 16 | it will transparently and automatically sign the assemblies you reference as 17 | part of the build process. 18 | 19 | # Demo 20 | 21 | Here's how to try Strong Namer out for yourself: 22 | 23 | - Create a new Console application 24 | - Add a strong name to the application 25 | - *Go to the Signing tab of the project properties* 26 | - *Check "Sign the assembly"* 27 | - *In the key file dropdown, choose <New...>* 28 | - *Choose a key file name (ie "key.snk"), uncheck the password option, 29 | and click OK* 30 | - Add a reference to the [Octokit](https://www.nuget.org/packages/octokit) 31 | NuGet package 32 | - Replace Program class with the following code: 33 | 34 | ``` C# 35 | using Octokit; 36 | using System; 37 | using System.Collections.Generic; 38 | using System.Linq; 39 | using System.Text; 40 | using System.Threading.Tasks; 41 | 42 | class Program 43 | { 44 | static void Main(string[] args) 45 | { 46 | MainAsyncWithErrorHandling().Wait(); 47 | } 48 | 49 | static async Task MainAsyncWithErrorHandling() 50 | { 51 | try 52 | { 53 | await MainAsync(); 54 | } 55 | catch (Exception ex) 56 | { 57 | Console.WriteLine(ex.ToString()); 58 | } 59 | } 60 | 61 | static async Task MainAsync() 62 | { 63 | var github = new GitHubClient(new ProductHeaderValue("MyAmazingApp")); 64 | var user = await github.User.Get("half-ogre"); 65 | Console.WriteLine(user.Followers + " folks love the half ogre!"); 66 | } 67 | } 68 | ``` 69 | - Start without debugging (CTRL+F5) 70 | 71 | ![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) 72 | File name: 'Octokit, Version=0.16.0.0, Culture=neutral, PublicKeyToken=null' 73 | at Program.MainAsync() 74 | at Program.d__1.MoveNext() in C:\Users\daplaist\Documents\Visual Studio 2015\Projects\ConsoleApplication13\ConsoleApplication13\Program.cs:line 19](images/StrongNameSadPanda.png) 75 | - :disappointed: 76 | - Add a reference to the [StrongNamer](https://www.nuget.org/packages/strongnamer) 77 | NuGet package 78 | - Start without debugging (CTRL+F5) 79 | 80 | ![75 folks love the half ogre!](images/StrongNameSuccessSparkles.png) 81 | - :sparkles: :fireworks: :smile: :fireworks: :sparkles: 82 | 83 | # How does it work? 84 | 85 | The NuGet package includes an MSBuild targets file and task which hook into the 86 | build process and add a strong name to any references which aren't strong named 87 | just before they are passed to the compiler. 88 | 89 | The task uses Mono.Cecil to do this. Credit goes to [Nivot.StrongNaming](https://github.com/oising/strongnaming) for showing me how 90 | to do this. 91 | 92 | # Options 93 | 94 | 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). 95 | -------------------------------------------------------------------------------- /StrongNamer.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.26510.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StrongNamer", "src\StrongNamer\StrongNamer.csproj", "{3BED6CCE-6803-448D-90D7-86EB9699CEA7}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestLibrary", "src\TestLibrary\TestLibrary.csproj", "{2823F067-39ED-4FE1-96C4-72C93A68DB8E}" 9 | ProjectSection(ProjectDependencies) = postProject 10 | {3BED6CCE-6803-448D-90D7-86EB9699CEA7} = {3BED6CCE-6803-448D-90D7-86EB9699CEA7} 11 | EndProjectSection 12 | EndProject 13 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestConsoleApp", "src\TestConsoleApp\TestConsoleApp.csproj", "{2F57F75B-02A7-44DE-B49F-5CA81546AF9B}" 14 | EndProject 15 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{3CBEB2ED-9680-44EF-B22B-7E91D758D672}" 16 | ProjectSection(SolutionItems) = preProject 17 | build\build.proj = build\build.proj 18 | build\Build.tasks = build\Build.tasks 19 | EndProjectSection 20 | EndProject 21 | Global 22 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 23 | Debug|Any CPU = Debug|Any CPU 24 | Release|Any CPU = Release|Any CPU 25 | EndGlobalSection 26 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 27 | {3BED6CCE-6803-448D-90D7-86EB9699CEA7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 28 | {3BED6CCE-6803-448D-90D7-86EB9699CEA7}.Debug|Any CPU.Build.0 = Debug|Any CPU 29 | {3BED6CCE-6803-448D-90D7-86EB9699CEA7}.Release|Any CPU.ActiveCfg = Release|Any CPU 30 | {3BED6CCE-6803-448D-90D7-86EB9699CEA7}.Release|Any CPU.Build.0 = Release|Any CPU 31 | {2823F067-39ED-4FE1-96C4-72C93A68DB8E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 32 | {2823F067-39ED-4FE1-96C4-72C93A68DB8E}.Debug|Any CPU.Build.0 = Debug|Any CPU 33 | {2823F067-39ED-4FE1-96C4-72C93A68DB8E}.Release|Any CPU.ActiveCfg = Release|Any CPU 34 | {2823F067-39ED-4FE1-96C4-72C93A68DB8E}.Release|Any CPU.Build.0 = Release|Any CPU 35 | {2F57F75B-02A7-44DE-B49F-5CA81546AF9B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 36 | {2F57F75B-02A7-44DE-B49F-5CA81546AF9B}.Debug|Any CPU.Build.0 = Debug|Any CPU 37 | {2F57F75B-02A7-44DE-B49F-5CA81546AF9B}.Release|Any CPU.ActiveCfg = Release|Any CPU 38 | {2F57F75B-02A7-44DE-B49F-5CA81546AF9B}.Release|Any CPU.Build.0 = Release|Any CPU 39 | EndGlobalSection 40 | GlobalSection(SolutionProperties) = preSolution 41 | HideSolutionNode = FALSE 42 | EndGlobalSection 43 | EndGlobal 44 | -------------------------------------------------------------------------------- /azure-pipelines.yml: -------------------------------------------------------------------------------- 1 | trigger: 2 | branches: 3 | include: 4 | - master 5 | - rel/* 6 | paths: 7 | exclude: 8 | - '**/*.md' 9 | 10 | pr: 11 | branches: 12 | include: 13 | - master 14 | - rel/* 15 | paths: 16 | exclude: 17 | - '**/*.md' 18 | 19 | variables: 20 | DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true 21 | 22 | stages: 23 | - stage: Build 24 | jobs: 25 | - job: Build 26 | pool: 27 | vmImage: windows-latest 28 | 29 | variables: 30 | BuildConfiguration: Release 31 | 32 | steps: 33 | - task: DotNetCoreCLI@2 34 | inputs: 35 | command: custom 36 | custom: tool 37 | arguments: install --tool-path . nbgv 38 | displayName: Install NBGV tool 39 | 40 | - script: nbgv cloud 41 | displayName: Set Version 42 | 43 | - task: UseDotNet@2 44 | displayName: Use .NET Core 3.0.x SDK 45 | inputs: 46 | version: 3.0.x 47 | performMultiLevelLookup: true 48 | 49 | 50 | - task: DotNetCoreCLI@2 51 | inputs: 52 | command: build 53 | projects: src/StrongNamer/StrongNamer.csproj 54 | arguments: -p:Configuration=$(BuildConfiguration) 55 | displayName: Build StrongNamer 56 | 57 | - task: DotNetCoreCLI@2 58 | inputs: 59 | command: pack 60 | packagesToPack: src/StrongNamer/StrongNamer.csproj 61 | configuration: $(BuildConfiguration) 62 | packDirectory: $(Build.ArtifactStagingDirectory)\artifacts 63 | displayName: Pack StrongNamer 64 | 65 | - publish: $(Build.ArtifactStagingDirectory)\artifacts 66 | displayName: Publish build packages 67 | artifact: BuildPackages 68 | -------------------------------------------------------------------------------- /images/StrongNameSadPanda.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dsplaisted/strongnamer/7c8f96199a6e22e01963414bc6b23478ad79a497/images/StrongNameSadPanda.png -------------------------------------------------------------------------------- /images/StrongNameSuccessSparkles.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dsplaisted/strongnamer/7c8f96199a6e22e01963414bc6b23478ad79a497/images/StrongNameSuccessSparkles.png -------------------------------------------------------------------------------- /src/StrongNamer/AddStrongName.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Build.Framework; 2 | using Microsoft.Build.Utilities; 3 | using Mono.Cecil; 4 | using Mono.Security.Cryptography; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.IO; 8 | using System.Linq; 9 | using System.Reflection; 10 | using System.Security.Cryptography; 11 | using System.Text; 12 | using System.Threading; 13 | using System.Threading.Tasks; 14 | 15 | namespace StrongNamer 16 | { 17 | public class AddStrongName : Microsoft.Build.Utilities.Task 18 | { 19 | [Required] 20 | public ITaskItem[] Assemblies { get; set; } 21 | 22 | [Required] 23 | public ITaskItem SignedAssemblyFolder { get; set; } 24 | 25 | public ITaskItem[] CopyLocalFiles { get; set; } 26 | 27 | [Output] 28 | public ITaskItem[] SignedAssembliesToReference { get; set; } 29 | 30 | [Output] 31 | public ITaskItem[] NewCopyLocalFiles { get; set; } 32 | 33 | [Required] 34 | public ITaskItem KeyFile { get; set; } 35 | 36 | public override bool Execute() 37 | { 38 | if (Assemblies == null || Assemblies.Length == 0) 39 | { 40 | return true; 41 | } 42 | 43 | if (SignedAssemblyFolder == null || string.IsNullOrEmpty(SignedAssemblyFolder.ItemSpec)) 44 | { 45 | Log.LogError($"{nameof(SignedAssemblyFolder)} not specified"); 46 | return false; 47 | } 48 | 49 | if (KeyFile == null || string.IsNullOrEmpty(KeyFile.ItemSpec)) 50 | { 51 | Log.LogError("KeyFile not specified"); 52 | return false; 53 | } 54 | 55 | if (!File.Exists(KeyFile.ItemSpec)) 56 | { 57 | Log.LogError($"KeyFile not found: ${KeyFile.ItemSpec}"); 58 | return false; 59 | } 60 | 61 | var keyBytes = File.ReadAllBytes(KeyFile.ItemSpec); 62 | 63 | SignedAssembliesToReference = new ITaskItem[Assemblies.Length]; 64 | 65 | Dictionary updatedReferencePaths = new Dictionary(); 66 | 67 | using (var resolver = new StrongNamerAssemblyResolver(Assemblies.Select(a => a.ItemSpec))) 68 | { 69 | for (int i = 0; i < Assemblies.Length; i++) 70 | { 71 | SignedAssembliesToReference[i] = ProcessAssembly(Assemblies[i], keyBytes, resolver); 72 | if (SignedAssembliesToReference[i].ItemSpec != Assemblies[i].ItemSpec) 73 | { 74 | // Path was updated to signed version 75 | updatedReferencePaths[Assemblies[i].ItemSpec] = SignedAssembliesToReference[i].ItemSpec; 76 | } 77 | } 78 | } 79 | 80 | if (CopyLocalFiles != null) 81 | { 82 | NewCopyLocalFiles = new ITaskItem[CopyLocalFiles.Length]; 83 | for (int i=0; i< CopyLocalFiles.Length; i++) 84 | { 85 | string updatedPath; 86 | if (updatedReferencePaths.TryGetValue(CopyLocalFiles[i].ItemSpec, out updatedPath)) 87 | { 88 | NewCopyLocalFiles[i] = new TaskItem(CopyLocalFiles[i]); 89 | NewCopyLocalFiles[i].ItemSpec = updatedPath; 90 | } 91 | else 92 | { 93 | NewCopyLocalFiles[i] = CopyLocalFiles[i]; 94 | } 95 | } 96 | } 97 | 98 | return true; 99 | } 100 | 101 | ITaskItem ProcessAssembly(ITaskItem assemblyItem, byte[] keyBytes, StrongNamerAssemblyResolver resolver) 102 | { 103 | string signedAssemblyFolder = Path.GetFullPath(SignedAssemblyFolder.ItemSpec); 104 | if (!Directory.Exists(signedAssemblyFolder)) 105 | { 106 | Directory.CreateDirectory(signedAssemblyFolder); 107 | } 108 | 109 | string assemblyOutputPath = Path.Combine(signedAssemblyFolder, Path.GetFileName(assemblyItem.ItemSpec)); 110 | 111 | // Check if the signed assembly for this assembly already exists and the Mvid matches. 112 | // Avoid doing the work again if we can just re-use the existing assembly. 113 | // This also helps with build incrementality since we won't touch the timestamp of the signed 114 | // assembly if it didn't change (thus invalidating the entire build that depends on it). 115 | Guid existingAssemblyMvid = Guid.Empty; 116 | if (File.Exists(assemblyOutputPath)) 117 | { 118 | try 119 | { 120 | using (var existingModule = ModuleDefinition.ReadModule(assemblyOutputPath)) 121 | { 122 | existingAssemblyMvid = existingModule.Mvid; 123 | } 124 | } 125 | catch (Exception ex) 126 | { 127 | Log.LogMessage(MessageImportance.High, $"Assembly file '{assemblyItem.ItemSpec}' failed to load. Skipping. {ex}"); 128 | throw; 129 | } 130 | } 131 | 132 | if (!File.Exists(assemblyItem.ItemSpec)) 133 | { 134 | Log.LogMessage(MessageImportance.Low, $"Assembly file '{assemblyItem.ItemSpec}' does not exist (yet). Skipping."); 135 | return assemblyItem; 136 | } 137 | 138 | using (var assembly = AssemblyDefinition.ReadAssembly(assemblyItem.ItemSpec, new ReaderParameters() 139 | { 140 | AssemblyResolver = resolver 141 | })) 142 | { 143 | if (assembly.Name.HasPublicKey) 144 | { 145 | Log.LogMessage(MessageImportance.Low, $"Assembly file '{assemblyItem.ItemSpec}' is already signed. Skipping."); 146 | return assemblyItem; 147 | } 148 | 149 | if (existingAssemblyMvid != Guid.Empty && assembly.MainModule.Mvid == existingAssemblyMvid) 150 | { 151 | Log.LogMessage(MessageImportance.Low, $"Signed assembly already exists for '{assemblyItem.ItemSpec}' and the Mvid matches. Using existing signed assembly."); 152 | 153 | assemblyItem = new TaskItem(assemblyItem); 154 | assemblyItem.ItemSpec = assemblyOutputPath; 155 | return assemblyItem; 156 | } 157 | 158 | 159 | var publicKey = GetPublicKey(keyBytes); 160 | 161 | var token = GetKeyTokenFromKey(publicKey); 162 | 163 | string formattedKeyToken = BitConverter.ToString(token).Replace("-", ""); 164 | Log.LogMessage(MessageImportance.Low, $"Signing assembly {assembly.FullName} with key with token {formattedKeyToken}"); 165 | 166 | assembly.Name.HashAlgorithm = Mono.Cecil.AssemblyHashAlgorithm.SHA1; 167 | assembly.Name.PublicKey = publicKey; 168 | assembly.Name.HasPublicKey = true; 169 | assembly.Name.Attributes &= AssemblyAttributes.PublicKey; 170 | 171 | foreach (var reference in assembly.MainModule.AssemblyReferences.Where(r => r.PublicKeyToken == null || r.PublicKeyToken.Length == 0)) 172 | { 173 | reference.PublicKeyToken = token; 174 | Log.LogMessage(MessageImportance.Low, $"Updating reference in assembly {assembly.FullName} to {reference.FullName} to use token {formattedKeyToken}"); 175 | } 176 | 177 | string fullPublicKey = BitConverter.ToString(publicKey).Replace("-", ""); 178 | 179 | var internalsVisibleToAttributes = assembly.CustomAttributes.Where(att => att.AttributeType.FullName == typeof(System.Runtime.CompilerServices.InternalsVisibleToAttribute).FullName).ToList(); 180 | foreach (var internalsVisibleToAttribute in internalsVisibleToAttributes) 181 | { 182 | string internalsVisibleToAssemblyName = (string)internalsVisibleToAttribute.ConstructorArguments[0].Value; 183 | string newInternalsVisibleToAssemblyName = internalsVisibleToAssemblyName + ", PublicKey=" + fullPublicKey; 184 | Log.LogMessage(MessageImportance.Low, $"Updating InternalsVisibleToAttribute in {assembly.FullName} from {internalsVisibleToAssemblyName} to {newInternalsVisibleToAssemblyName}"); 185 | 186 | internalsVisibleToAttribute.ConstructorArguments[0] = new CustomAttributeArgument(internalsVisibleToAttribute.ConstructorArguments[0].Type, newInternalsVisibleToAssemblyName); 187 | } 188 | 189 | Log.LogMessage(MessageImportance.Low, $"Writing signed assembly to {assemblyOutputPath}"); 190 | try 191 | { 192 | assembly.Write(assemblyOutputPath, new WriterParameters() 193 | { 194 | StrongNameKeyBlob = keyBytes 195 | }); 196 | } 197 | catch (Exception ex) 198 | { 199 | Log.LogMessage(MessageImportance.High, $"Failed to write signed assembly to '{assemblyOutputPath}'. {ex}"); 200 | File.Delete(assemblyOutputPath); 201 | } 202 | 203 | var ret = new TaskItem(assemblyItem); 204 | ret.ItemSpec = assemblyOutputPath; 205 | 206 | return ret; 207 | } 208 | } 209 | 210 | private static byte[] GetKeyTokenFromKey(byte[] fullKey) 211 | { 212 | byte[] hash; 213 | using (var sha1 = SHA1.Create()) 214 | { 215 | hash = sha1.ComputeHash(fullKey); 216 | } 217 | 218 | return hash.Reverse().Take(8).ToArray(); 219 | } 220 | 221 | // From Cecil 222 | // https://github.com/jbevain/cecil/pull/548/files 223 | static RSA CreateRSA(byte[] blob) 224 | { 225 | if (blob == null) 226 | throw new ArgumentNullException("blob"); 227 | 228 | 229 | return CryptoConvert.FromCapiKeyBlob(blob); 230 | } 231 | 232 | // https://github.com/atykhyy/cecil/blob/291a779d473e9c88e597e2c9f86e47e23b49be1e/Mono.Security.Cryptography/CryptoService.cs 233 | public static byte[] GetPublicKey(byte[] keyBlob) 234 | { 235 | using var rsa = CreateRSA(keyBlob); 236 | 237 | var cspBlob = CryptoConvert.ToCapiPublicKeyBlob(rsa); 238 | var publicKey = new byte[12 + cspBlob.Length]; 239 | Buffer.BlockCopy(cspBlob, 0, publicKey, 12, cspBlob.Length); 240 | // The first 12 bytes are documented at: 241 | // http://msdn.microsoft.com/library/en-us/cprefadd/html/grfungethashfromfile.asp 242 | // ALG_ID - Signature 243 | publicKey[1] = 36; 244 | // ALG_ID - Hash 245 | publicKey[4] = 4; 246 | publicKey[5] = 128; 247 | // Length of Public Key (in bytes) 248 | publicKey[8] = (byte)(cspBlob.Length >> 0); 249 | publicKey[9] = (byte)(cspBlob.Length >> 8); 250 | publicKey[10] = (byte)(cspBlob.Length >> 16); 251 | publicKey[11] = (byte)(cspBlob.Length >> 24); 252 | return publicKey; 253 | } 254 | 255 | } 256 | } 257 | -------------------------------------------------------------------------------- /src/StrongNamer/CryptoConvert.cs: -------------------------------------------------------------------------------- 1 | // 2 | // CryptoConvert.cs - Crypto Convertion Routines 3 | // 4 | // Author: 5 | // Sebastien Pouliot 6 | // 7 | // (C) 2003 Motus Technologies Inc. (http://www.motus.com) 8 | // Copyright (C) 2004-2006 Novell Inc. (http://www.novell.com) 9 | // 10 | // Permission is hereby granted, free of charge, to any person obtaining 11 | // a copy of this software and associated documentation files (the 12 | // "Software"), to deal in the Software without restriction, including 13 | // without limitation the rights to use, copy, modify, merge, publish, 14 | // distribute, sublicense, and/or sell copies of the Software, and to 15 | // permit persons to whom the Software is furnished to do so, subject to 16 | // the following conditions: 17 | // 18 | // The above copyright notice and this permission notice shall be 19 | // included in all copies or substantial portions of the Software. 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 22 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 23 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 24 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 25 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 26 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 27 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 28 | // 29 | 30 | using System; 31 | using System.Security.Cryptography; 32 | 33 | namespace Mono.Security.Cryptography 34 | { 35 | 36 | static class CryptoConvert 37 | { 38 | 39 | static private int ToInt32LE(byte[] bytes, int offset) 40 | { 41 | return (bytes[offset + 3] << 24) | (bytes[offset + 2] << 16) | (bytes[offset + 1] << 8) | bytes[offset]; 42 | } 43 | 44 | static private uint ToUInt32LE(byte[] bytes, int offset) 45 | { 46 | return (uint)((bytes[offset + 3] << 24) | (bytes[offset + 2] << 16) | (bytes[offset + 1] << 8) | bytes[offset]); 47 | } 48 | 49 | static private byte[] GetBytesLE(int val) 50 | { 51 | return new byte[] { 52 | (byte) (val & 0xff), 53 | (byte) ((val >> 8) & 0xff), 54 | (byte) ((val >> 16) & 0xff), 55 | (byte) ((val >> 24) & 0xff) 56 | }; 57 | } 58 | 59 | static private byte[] Trim(byte[] array) 60 | { 61 | for (int i = 0; i < array.Length; i++) 62 | { 63 | if (array[i] != 0x00) 64 | { 65 | byte[] result = new byte[array.Length - i]; 66 | Buffer.BlockCopy(array, i, result, 0, result.Length); 67 | return result; 68 | } 69 | } 70 | return null; 71 | } 72 | 73 | static RSA FromCapiPrivateKeyBlob(byte[] blob, int offset) 74 | { 75 | RSAParameters rsap = new RSAParameters(); 76 | try 77 | { 78 | if ((blob[offset] != 0x07) || // PRIVATEKEYBLOB (0x07) 79 | (blob[offset + 1] != 0x02) || // Version (0x02) 80 | (blob[offset + 2] != 0x00) || // Reserved (word) 81 | (blob[offset + 3] != 0x00) || 82 | (ToUInt32LE(blob, offset + 8) != 0x32415352)) // DWORD magic = RSA2 83 | throw new CryptographicException("Invalid blob header"); 84 | 85 | // ALGID (CALG_RSA_SIGN, CALG_RSA_KEYX, ...) 86 | // int algId = ToInt32LE (blob, offset+4); 87 | 88 | // DWORD bitlen 89 | int bitLen = ToInt32LE(blob, offset + 12); 90 | 91 | // DWORD public exponent 92 | byte[] exp = new byte[4]; 93 | Buffer.BlockCopy(blob, offset + 16, exp, 0, 4); 94 | Array.Reverse(exp); 95 | rsap.Exponent = Trim(exp); 96 | 97 | int pos = offset + 20; 98 | // BYTE modulus[rsapubkey.bitlen/8]; 99 | int byteLen = (bitLen >> 3); 100 | rsap.Modulus = new byte[byteLen]; 101 | Buffer.BlockCopy(blob, pos, rsap.Modulus, 0, byteLen); 102 | Array.Reverse(rsap.Modulus); 103 | pos += byteLen; 104 | 105 | // BYTE prime1[rsapubkey.bitlen/16]; 106 | int byteHalfLen = (byteLen >> 1); 107 | rsap.P = new byte[byteHalfLen]; 108 | Buffer.BlockCopy(blob, pos, rsap.P, 0, byteHalfLen); 109 | Array.Reverse(rsap.P); 110 | pos += byteHalfLen; 111 | 112 | // BYTE prime2[rsapubkey.bitlen/16]; 113 | rsap.Q = new byte[byteHalfLen]; 114 | Buffer.BlockCopy(blob, pos, rsap.Q, 0, byteHalfLen); 115 | Array.Reverse(rsap.Q); 116 | pos += byteHalfLen; 117 | 118 | // BYTE exponent1[rsapubkey.bitlen/16]; 119 | rsap.DP = new byte[byteHalfLen]; 120 | Buffer.BlockCopy(blob, pos, rsap.DP, 0, byteHalfLen); 121 | Array.Reverse(rsap.DP); 122 | pos += byteHalfLen; 123 | 124 | // BYTE exponent2[rsapubkey.bitlen/16]; 125 | rsap.DQ = new byte[byteHalfLen]; 126 | Buffer.BlockCopy(blob, pos, rsap.DQ, 0, byteHalfLen); 127 | Array.Reverse(rsap.DQ); 128 | pos += byteHalfLen; 129 | 130 | // BYTE coefficient[rsapubkey.bitlen/16]; 131 | rsap.InverseQ = new byte[byteHalfLen]; 132 | Buffer.BlockCopy(blob, pos, rsap.InverseQ, 0, byteHalfLen); 133 | Array.Reverse(rsap.InverseQ); 134 | pos += byteHalfLen; 135 | 136 | // ok, this is hackish but CryptoAPI support it so... 137 | // note: only works because CRT is used by default 138 | // http://bugzilla.ximian.com/show_bug.cgi?id=57941 139 | rsap.D = new byte[byteLen]; // must be allocated 140 | if (pos + byteLen + offset <= blob.Length) 141 | { 142 | // BYTE privateExponent[rsapubkey.bitlen/8]; 143 | Buffer.BlockCopy(blob, pos, rsap.D, 0, byteLen); 144 | Array.Reverse(rsap.D); 145 | } 146 | } 147 | catch (Exception e) 148 | { 149 | throw new CryptographicException("Invalid blob.", e); 150 | } 151 | 152 | RSA rsa = null; 153 | try 154 | { 155 | rsa = RSA.Create(); 156 | rsa.ImportParameters(rsap); 157 | } 158 | catch (CryptographicException) 159 | { 160 | // this may cause problem when this code is run under 161 | // the SYSTEM identity on Windows (e.g. ASP.NET). See 162 | // http://bugzilla.ximian.com/show_bug.cgi?id=77559 163 | bool throws = false; 164 | try 165 | { 166 | CspParameters csp = new CspParameters(); 167 | csp.Flags = CspProviderFlags.UseMachineKeyStore; 168 | rsa = new RSACryptoServiceProvider(csp); 169 | rsa.ImportParameters(rsap); 170 | } 171 | catch 172 | { 173 | throws = true; 174 | } 175 | 176 | if (throws) 177 | { 178 | // rethrow original, not the latter, exception if this fails 179 | throw; 180 | } 181 | } 182 | return rsa; 183 | } 184 | 185 | static RSA FromCapiPublicKeyBlob(byte[] blob, int offset) 186 | { 187 | try 188 | { 189 | if ((blob[offset] != 0x06) || // PUBLICKEYBLOB (0x06) 190 | (blob[offset + 1] != 0x02) || // Version (0x02) 191 | (blob[offset + 2] != 0x00) || // Reserved (word) 192 | (blob[offset + 3] != 0x00) || 193 | (ToUInt32LE(blob, offset + 8) != 0x31415352)) // DWORD magic = RSA1 194 | throw new CryptographicException("Invalid blob header"); 195 | 196 | // ALGID (CALG_RSA_SIGN, CALG_RSA_KEYX, ...) 197 | // int algId = ToInt32LE (blob, offset+4); 198 | 199 | // DWORD bitlen 200 | int bitLen = ToInt32LE(blob, offset + 12); 201 | 202 | // DWORD public exponent 203 | RSAParameters rsap = new RSAParameters(); 204 | rsap.Exponent = new byte[3]; 205 | rsap.Exponent[0] = blob[offset + 18]; 206 | rsap.Exponent[1] = blob[offset + 17]; 207 | rsap.Exponent[2] = blob[offset + 16]; 208 | 209 | int pos = offset + 20; 210 | // BYTE modulus[rsapubkey.bitlen/8]; 211 | int byteLen = (bitLen >> 3); 212 | rsap.Modulus = new byte[byteLen]; 213 | Buffer.BlockCopy(blob, pos, rsap.Modulus, 0, byteLen); 214 | Array.Reverse(rsap.Modulus); 215 | 216 | RSA rsa = null; 217 | try 218 | { 219 | rsa = RSA.Create(); 220 | rsa.ImportParameters(rsap); 221 | } 222 | catch (CryptographicException) 223 | { 224 | // this may cause problem when this code is run under 225 | // the SYSTEM identity on Windows (e.g. ASP.NET). See 226 | // http://bugzilla.ximian.com/show_bug.cgi?id=77559 227 | CspParameters csp = new CspParameters(); 228 | csp.Flags = CspProviderFlags.UseMachineKeyStore; 229 | rsa = new RSACryptoServiceProvider(csp); 230 | rsa.ImportParameters(rsap); 231 | } 232 | return rsa; 233 | } 234 | catch (Exception e) 235 | { 236 | throw new CryptographicException("Invalid blob.", e); 237 | } 238 | } 239 | 240 | // PRIVATEKEYBLOB 241 | // PUBLICKEYBLOB 242 | static public RSA FromCapiKeyBlob(byte[] blob) 243 | { 244 | return FromCapiKeyBlob(blob, 0); 245 | } 246 | 247 | static public RSA FromCapiKeyBlob(byte[] blob, int offset) 248 | { 249 | if (blob == null) 250 | throw new ArgumentNullException("blob"); 251 | if (offset >= blob.Length) 252 | throw new ArgumentException("blob is too small."); 253 | 254 | switch (blob[offset]) 255 | { 256 | case 0x00: 257 | // this could be a public key inside an header 258 | // like "sn -e" would produce 259 | if (blob[offset + 12] == 0x06) 260 | { 261 | return FromCapiPublicKeyBlob(blob, offset + 12); 262 | } 263 | break; 264 | case 0x06: 265 | return FromCapiPublicKeyBlob(blob, offset); 266 | case 0x07: 267 | return FromCapiPrivateKeyBlob(blob, offset); 268 | } 269 | throw new CryptographicException("Unknown blob format."); 270 | } 271 | 272 | static public byte[] ToCapiPublicKeyBlob(RSA rsa) 273 | { 274 | RSAParameters p = rsa.ExportParameters(false); 275 | int keyLength = p.Modulus.Length; // in bytes 276 | byte[] blob = new byte[20 + keyLength]; 277 | 278 | blob[0] = 0x06; // Type - PUBLICKEYBLOB (0x06) 279 | blob[1] = 0x02; // Version - Always CUR_BLOB_VERSION (0x02) 280 | // [2], [3] // RESERVED - Always 0 281 | blob[5] = 0x24; // ALGID - Always 00 24 00 00 (for CALG_RSA_SIGN) 282 | blob[8] = 0x52; // Magic - RSA1 (ASCII in hex) 283 | blob[9] = 0x53; 284 | blob[10] = 0x41; 285 | blob[11] = 0x31; 286 | 287 | byte[] bitlen = GetBytesLE(keyLength << 3); 288 | blob[12] = bitlen[0]; // bitlen 289 | blob[13] = bitlen[1]; 290 | blob[14] = bitlen[2]; 291 | blob[15] = bitlen[3]; 292 | 293 | // public exponent (DWORD) 294 | int pos = 16; 295 | int n = p.Exponent.Length; 296 | while (n > 0) 297 | blob[pos++] = p.Exponent[--n]; 298 | // modulus 299 | pos = 20; 300 | byte[] part = p.Modulus; 301 | int len = part.Length; 302 | Array.Reverse(part, 0, len); 303 | Buffer.BlockCopy(part, 0, blob, pos, len); 304 | pos += len; 305 | return blob; 306 | } 307 | } 308 | } -------------------------------------------------------------------------------- /src/StrongNamer/SharedKey.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dsplaisted/strongnamer/7c8f96199a6e22e01963414bc6b23478ad79a497/src/StrongNamer/SharedKey.snk -------------------------------------------------------------------------------- /src/StrongNamer/StrongNamer.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | net461;netcoreapp2.1 4 | SharedKey.snk 5 | true 6 | true 7 | Daniel Plaisted 8 | Strong Namer - Automatically Add Strong Names to References 9 | https://github.com/dsplaisted/strongnamer 10 | 11 | 12 | strongname strong name naming 13 | Strong Namer will automatically add strong names to referenced assemblies which do not already have a strong name. 14 | Strong Namer will 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. 15 | 16 | build 17 | $(NoWarn);NU5128 18 | 19 | 0.11.0 20 | latest 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /src/StrongNamer/StrongNamer.targets: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $(MSBuildProjectDirectory)\obj\$(Configuration)\ 5 | $(MSBuildThisFileDirectory)netcoreapp2.1\StrongNamer.dll 6 | $(MSBuildThisFileDirectory)net461\StrongNamer.dll 7 | 8 | 2.1 9 | 10 | $(BundledNETCoreAppTargetFrameworkVersion) 11 | 1.0 12 | 13 | 14 | 15 | 16 | 17 | 20 | 21 | 25 | 26 | 27 | $(MSBuildThisFileDirectory)SharedKey.snk 28 | 29 | 30 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | $(ResolveReferencesDependsOn);StrongNamerTarget 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /src/StrongNamer/StrongNamerAssemblyResolver.cs: -------------------------------------------------------------------------------- 1 | using Mono.Cecil; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | 6 | namespace StrongNamer 7 | { 8 | class StrongNamerAssemblyResolver : BaseAssemblyResolver 9 | { 10 | readonly string[] _assemblyPaths; 11 | List _assemblies = null; 12 | 13 | public StrongNamerAssemblyResolver(IEnumerable assemblyPaths) : base() 14 | { 15 | _assemblyPaths = assemblyPaths.ToArray(); 16 | } 17 | 18 | // If the base resolver can't resolve an assembly, look for assemblies which are referenced by the project 19 | // Base resolver checks local folders and the GAC, so will not find anything in the Packages folder 20 | public override AssemblyDefinition Resolve(AssemblyNameReference name, ReaderParameters parameters) 21 | { 22 | AssemblyDefinition matchedAssembly = null; 23 | try 24 | { 25 | matchedAssembly = base.Resolve(name, parameters); 26 | } 27 | catch (AssemblyResolutionException) 28 | { 29 | } 30 | 31 | if (matchedAssembly == null) 32 | { 33 | if (_assemblies == null) 34 | { 35 | _assemblies = _assemblyPaths 36 | .Where(File.Exists) 37 | .Select(AssemblyDefinition.ReadAssembly) 38 | .ToList(); 39 | } 40 | 41 | matchedAssembly = _assemblies.SingleOrDefault(ad => ad.Name.Name.Equals(name.Name)); 42 | } 43 | return matchedAssembly; 44 | } 45 | 46 | public override AssemblyDefinition Resolve(AssemblyNameReference name) 47 | { 48 | return Resolve(name, new ReaderParameters()); 49 | } 50 | 51 | protected override void Dispose(bool disposing) 52 | { 53 | base.Dispose(disposing); 54 | if(disposing) 55 | { 56 | if (_assemblies != null) 57 | { 58 | for (int i = 0; i < _assemblies.Count; i++) 59 | { 60 | _assemblies[i]?.Dispose(); 61 | } 62 | } 63 | } 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/TestConsoleApp/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /src/TestConsoleApp/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using TestLibrary; 8 | 9 | namespace TestConsoleApp 10 | { 11 | class Program 12 | { 13 | static void Main(string[] args) 14 | { 15 | MainAsync().Wait(); 16 | } 17 | 18 | static async Task MainAsync() 19 | { 20 | try 21 | { 22 | var test = new Class1(); 23 | await test.TestAsync(); 24 | } 25 | catch (Exception ex) 26 | { 27 | Console.WriteLine(ex.ToString()); 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/TestConsoleApp/TestConsoleApp.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | net461 4 | Exe 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /src/TestLibrary/Class1.cs: -------------------------------------------------------------------------------- 1 | using Octokit; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace TestLibrary 9 | { 10 | public class Class1 11 | { 12 | public async Task TestAsync() 13 | { 14 | var github = new GitHubClient(new ProductHeaderValue("MyAmazingApp")); 15 | var user = await github.User.Get("half-ogre"); 16 | Console.WriteLine(user.Followers + " folks love the half ogre!"); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/TestLibrary/SharedKey.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dsplaisted/strongnamer/7c8f96199a6e22e01963414bc6b23478ad79a497/src/TestLibrary/SharedKey.snk -------------------------------------------------------------------------------- /src/TestLibrary/TestLibrary.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | net461 4 | true 5 | SharedKey.snk 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /version.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2", 3 | "publicReleaseRefSpec": [ 4 | "^refs/heads/master$", // we release out of master 5 | "^refs/heads/rel/v\\d+\\.\\d+" // we also release branches starting with rel/vN.N 6 | ], 7 | "nugetPackageVersion":{ 8 | "semVer": 2 9 | } 10 | } 11 | --------------------------------------------------------------------------------