├── images ├── fody.png ├── postsharp.png ├── g-research.svg └── particular.svg ├── BasicFodyAddin ├── AssemblyToProcess │ ├── NamespaceConfig.cs │ ├── Class1.cs │ └── AssemblyToProcess.csproj ├── package_icon.png ├── BasicFodyAddin │ ├── key.snk │ ├── NamespaceAttribute.cs │ └── BasicFodyAddin.csproj ├── SmokeTest │ ├── FodyWeavers.xml │ ├── Readme.txt │ ├── SmokeTest.csproj │ └── FodyWeavers.xsd ├── BasicFodyAddin.Fody │ ├── BasicFodyAddin.Fody.csproj │ ├── BasicFodyAddin.Fody.xcf │ └── ModuleWeaver.cs ├── appveyor.yml ├── Directory.Build.props ├── Tests │ ├── WeaverTests.cs │ └── Tests.csproj ├── readme.md └── BasicFodyAddin.sln ├── pages ├── sample-solution.png ├── virtuosity-nuget.png ├── weavers-in-project.jpg ├── project-dependencies.png ├── mdsource │ ├── processedbyfody-class.source.md │ ├── strong-naming.source.md │ ├── donations.source.md │ ├── addin-discovery.source.md │ ├── addin-packaging.source.md │ ├── usage.source.md │ ├── common-errors.source.md │ ├── backers.source.md │ ├── in-solution-weaving.source.md │ ├── readme.source.md │ ├── supported-runtimes-and-ide.source.md │ ├── upgradeGuideV5.source.md │ ├── licensing-patron-faq.source.md │ ├── configuration.source.md │ ├── addins.source.md │ └── addin-development.source.md ├── processedbyfody-class.md ├── strong-naming.md ├── donations.md ├── addin-discovery.md ├── usage.md ├── common-errors.md ├── backers.md ├── in-solution-weaving.md ├── readme.md ├── supported-runtimes-and-ide.md ├── upgradeGuideV5.md ├── addin-packaging.md ├── licensing-patron-faq.md ├── configuration.md ├── addins.md └── addin-development.md ├── .github └── dependabot.yml ├── src ├── Directory.Build.props ├── RepoSync │ ├── RepoSync.csproj │ ├── Source │ │ ├── workflows │ │ │ └── on-push-do-docs.yml │ │ └── .editorconfig │ └── Program.cs ├── Docs │ ├── Docs.csproj │ └── MyLoggingWeaver.cs └── FodyHome.sln ├── .gitignore ├── mdsnippets.json ├── license.txt └── readme.md /images/fody.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fody/Home/HEAD/images/fody.png -------------------------------------------------------------------------------- /BasicFodyAddin/AssemblyToProcess/NamespaceConfig.cs: -------------------------------------------------------------------------------- 1 | [assembly: Namespace("TheNamespace")] -------------------------------------------------------------------------------- /images/postsharp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fody/Home/HEAD/images/postsharp.png -------------------------------------------------------------------------------- /pages/sample-solution.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fody/Home/HEAD/pages/sample-solution.png -------------------------------------------------------------------------------- /pages/virtuosity-nuget.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fody/Home/HEAD/pages/virtuosity-nuget.png -------------------------------------------------------------------------------- /pages/weavers-in-project.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fody/Home/HEAD/pages/weavers-in-project.jpg -------------------------------------------------------------------------------- /BasicFodyAddin/AssemblyToProcess/Class1.cs: -------------------------------------------------------------------------------- 1 | namespace AssemblyToProcess; 2 | 3 | class Class1 4 | { 5 | } -------------------------------------------------------------------------------- /BasicFodyAddin/package_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fody/Home/HEAD/BasicFodyAddin/package_icon.png -------------------------------------------------------------------------------- /pages/project-dependencies.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fody/Home/HEAD/pages/project-dependencies.png -------------------------------------------------------------------------------- /BasicFodyAddin/BasicFodyAddin/key.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fody/Home/HEAD/BasicFodyAddin/BasicFodyAddin/key.snk -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: nuget 4 | directory: "/" 5 | schedule: 6 | interval: daily 7 | open-pull-requests-limit: 10 -------------------------------------------------------------------------------- /pages/mdsource/processedbyfody-class.source.md: -------------------------------------------------------------------------------- 1 | # ProcessedByFody Class 2 | 3 | Fody adds a new class to 4 | 5 | `class ProcessedByFody` 6 | 7 | The purpose of this type is to flag that the assembly has been processed by Fody. -------------------------------------------------------------------------------- /BasicFodyAddin/SmokeTest/FodyWeavers.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | -------------------------------------------------------------------------------- /src/Directory.Build.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | true 5 | latest 6 | all 7 | low 8 | 9 | 10 | -------------------------------------------------------------------------------- /BasicFodyAddin/BasicFodyAddin.Fody/BasicFodyAddin.Fody.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /BasicFodyAddin/appveyor.yml: -------------------------------------------------------------------------------- 1 | image: Visual Studio 2022 2 | skip_commits: 3 | message: /docs|Merge pull request.*/ 4 | build_script: 5 | - ps: >- 6 | dotnet build BasicFodyAddin --configuration Release 7 | 8 | dotnet test BasicFodyAddin --configuration Release --no-build --no-restore 9 | test: off 10 | artifacts: 11 | - path: nugets\*.nupkg -------------------------------------------------------------------------------- /src/RepoSync/RepoSync.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | Exe 4 | net7.0 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /BasicFodyAddin/AssemblyToProcess/AssemblyToProcess.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net48;net7.0 5 | true 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /BasicFodyAddin/BasicFodyAddin.Fody/BasicFodyAddin.Fody.xcf: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | Namespace to use for the injected type 7 | 8 | 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # User-specific files 3 | *.suo 4 | 5 | # Build results 6 | [Dd]ebug/ 7 | [Rr]elease/ 8 | x64/ 9 | x86/ 10 | [Bb]in/ 11 | [Oo]bj/ 12 | [Ll]og/ 13 | 14 | # Visual Studio 2015 cache/options directory 15 | .vs/ 16 | 17 | # .NET Core 18 | project.lock.json 19 | project.fragment.lock.json 20 | artifacts/ 21 | 22 | *.DotSettings.user 23 | 24 | nugets/ 25 | BasicFodyAddin/.idea/* 26 | .idea/* 27 | -------------------------------------------------------------------------------- /BasicFodyAddin/SmokeTest/Readme.txt: -------------------------------------------------------------------------------- 1 | This project ensures that the weaver works fine with the various target frameworks. 2 | 3 | It just runs the weaver and verifies the assembly. 4 | 5 | This simple test proves that the target framework of the target assembly does not really matter, since the IL will be always the same, 6 | as long as the weaved code does not require any special type or method from a specific framework. -------------------------------------------------------------------------------- /BasicFodyAddin/BasicFodyAddin/NamespaceAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | /// 4 | /// Namespace to use. 5 | /// 6 | [AttributeUsage(AttributeTargets.Assembly)] 7 | public class NamespaceAttribute : Attribute 8 | { 9 | /// 10 | /// Initialize a new instance of 11 | /// 12 | public NamespaceAttribute(string @namespace) 13 | { 14 | } 15 | } -------------------------------------------------------------------------------- /mdsnippets.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://raw.githubusercontent.com/SimonCropp/MarkdownSnippets/master/schema.json", 3 | "UrlsAsSnippets": [ 4 | "https://raw.githubusercontent.com/Fody/Fody/master/FodyPackaging/Weaver.props", 5 | "https://raw.githubusercontent.com/Fody/Fody/master/FodyPackaging/build/FodyPackaging.props", 6 | "https://raw.githubusercontent.com/Fody/Fody/master/FodyPackaging/build/FodyPackaging.targets" 7 | ], 8 | "ValidateContent": true 9 | } -------------------------------------------------------------------------------- /BasicFodyAddin/Directory.Build.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | true 5 | 1.2.0 6 | latest 7 | false 8 | NU1903 9 | all 10 | low 11 | 12 | -------------------------------------------------------------------------------- /pages/processedbyfody-class.md: -------------------------------------------------------------------------------- 1 | 7 | 8 | # ProcessedByFody Class 9 | 10 | Fody adds a new class to 11 | 12 | `class ProcessedByFody` 13 | 14 | The purpose of this type is to flag that the assembly has been processed by Fody. 15 | -------------------------------------------------------------------------------- /BasicFodyAddin/SmokeTest/SmokeTest.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | net472;netstandard2.0 4 | false 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /BasicFodyAddin/Tests/WeaverTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Fody; 3 | using Xunit; 4 | 5 | #region WeaverTests 6 | 7 | public class WeaverTests 8 | { 9 | static TestResult testResult; 10 | 11 | static WeaverTests() 12 | { 13 | var weavingTask = new ModuleWeaver(); 14 | testResult = weavingTask.ExecuteTestRun("AssemblyToProcess.dll"); 15 | } 16 | 17 | [Fact] 18 | public void ValidateHelloWorldIsInjected() 19 | { 20 | var type = testResult.Assembly.GetType("TheNamespace.Hello"); 21 | var instance = (dynamic)Activator.CreateInstance(type); 22 | 23 | Assert.Equal("Hello World", instance.World()); 24 | } 25 | } 26 | 27 | #endregion -------------------------------------------------------------------------------- /src/Docs/Docs.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | net7.0 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /pages/mdsource/strong-naming.source.md: -------------------------------------------------------------------------------- 1 | # Assembly Strong Naming 2 | 3 | Fody looks for the two settings that indicate a project file has produced a [strong named](https://docs.microsoft.com/en-us/dotnet/framework/app-domains/strong-named-assemblies) assembly. 4 | 5 | 6 | ## SignAssembly 7 | 8 | ```xml 9 | 10 | true 11 | 12 | ``` 13 | 14 | 15 | ## AssemblyOriginatorKeyFile 16 | 17 | ```xml 18 | 19 | Key.snk 20 | 21 | ``` 22 | 23 | So if `SignAssembly` is true and `AssemblyOriginatorKeyFile` contains a valid path to a key file then the resultant processed assembly will be strong named. -------------------------------------------------------------------------------- /src/RepoSync/Source/workflows/on-push-do-docs.yml: -------------------------------------------------------------------------------- 1 | name: on-push-do-docs 2 | on: 3 | push: 4 | jobs: 5 | docs: 6 | runs-on: windows-latest 7 | steps: 8 | - uses: actions/checkout@v2 9 | - name: Run MarkdownSnippets 10 | run: | 11 | dotnet tool install --global MarkdownSnippets.Tool 12 | mdsnippets ${GITHUB_WORKSPACE} 13 | shell: bash 14 | - name: Push changes 15 | run: | 16 | git config --local user.email "action@github.com" 17 | git config --local user.name "GitHub Action" 18 | git commit -m "Docs changes" -a || echo "nothing to commit" 19 | remote="https://${GITHUB_ACTOR}:${{secrets.GITHUB_TOKEN}}@github.com/${GITHUB_REPOSITORY}.git" 20 | branch="${GITHUB_REF:11}" 21 | git push "${remote}" ${branch} || echo "nothing to push" 22 | shell: bash -------------------------------------------------------------------------------- /BasicFodyAddin/Tests/Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net48;net7.0 5 | true 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /pages/strong-naming.md: -------------------------------------------------------------------------------- 1 | 7 | 8 | # Assembly Strong Naming 9 | 10 | Fody looks for the two settings that indicate a project file has produced a [strong named](https://docs.microsoft.com/en-us/dotnet/framework/app-domains/strong-named-assemblies) assembly. 11 | 12 | 13 | ## SignAssembly 14 | 15 | ```xml 16 | 17 | true 18 | 19 | ``` 20 | 21 | 22 | ## AssemblyOriginatorKeyFile 23 | 24 | ```xml 25 | 26 | Key.snk 27 | 28 | ``` 29 | 30 | So if `SignAssembly` is true and `AssemblyOriginatorKeyFile` contains a valid path to a key file then the resultant processed assembly will be strong named. 31 | -------------------------------------------------------------------------------- /license.txt: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) Simon Cropp and contributors 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 13 | all 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 21 | THE SOFTWARE. -------------------------------------------------------------------------------- /BasicFodyAddin/BasicFodyAddin/BasicFodyAddin.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net452;netstandard2.0;netstandard2.1 5 | true 6 | key.snk 7 | Simon Cropp 8 | Copyright $([System.DateTime]::UtcNow.ToString(yyyy)). 9 | Injects a new type that writes "Hello World". 10 | MIT 11 | 12 | Hello World, ILWeaving, Fody, Cecil, AOP 13 | $(SolutionDir)../nugets 14 | https://github.com/Fody/Home/tree/master/BasicFodyAddin 15 | https://raw.githubusercontent.com/Fody/Home/master/BasicFodyAddin/package_icon.png 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /BasicFodyAddin/readme.md: -------------------------------------------------------------------------------- 1 | [![NuGet Status](https://img.shields.io/nuget/v/BasicFodyAddin.Fody.svg)](https://www.nuget.org/packages/BasicFodyAddin.Fody/) 2 | 3 | ![Icon](https://raw.githubusercontent.com/Fody/Home/master/BasicFodyAddin/package_icon.png) 4 | 5 | This is a simple solution used to illustrate how to [write a Fody addin](/pages/addin-development.md). 6 | 7 | 8 | ## Usage 9 | 10 | See also [Fody usage](/pages/usage.md). 11 | 12 | 13 | ### NuGet installation 14 | 15 | Install the [BasicFodyAddin.Fody NuGet package](https://www.nuget.org/packages/BasicFodyAddin.Fody/) and update the [Fody NuGet package](https://www.nuget.org/packages/Fody/): 16 | 17 | ```powershell 18 | PM> Install-Package Fody 19 | PM> Install-Package BasicFodyAddin.Fody 20 | ``` 21 | 22 | The `Install-Package Fody` is required since NuGet always defaults to the oldest, and most buggy, version of any dependency. 23 | 24 | 25 | ### Add to FodyWeavers.xml 26 | 27 | Add `` to [FodyWeavers.xml](/pages/configuration.md#fodyweaversxml) 28 | 29 | ```xml 30 | 31 | 32 | 33 | ``` 34 | 35 | 36 | ## The moving parts 37 | 38 | See [writing an addin](/pages/addin-development.md) 39 | 40 | 41 | ## Icon 42 | 43 | [Lego](https://thenounproject.com/term/lego/16919/) designed by [Timur Zima](https://thenounproject.com/timur.zima/) from [The Noun Project](https://thenounproject.com). -------------------------------------------------------------------------------- /pages/mdsource/donations.source.md: -------------------------------------------------------------------------------- 1 | # Donations 2 | 3 | Every month the Fody project will donate a portion of funding raised to a charity or other cause. 4 | 5 | 6 | ## History 7 | 8 | * 2019 October: $50AUD to [Yalari](https://www.yalari.org/) 9 | * 2019 June: $50USD to [Diversify Tech](https://www.diversifytech.co/) as nominated by [Indu Alagarsamy](https://indu.dev/) 10 | * 2019 May: $50USD to [Women in Tech Podcast](http://podcast.womenintechshow.com/) by [Espree Devora](https://twitter.com/EspreeDevora) 11 | * 2019 May: $50USD to [Girl Develop It](https://www.girldevelopit.com/) 12 | * 2019 February: $50USD to [Ada Developers Academy](https://www.adadevelopersacademy.org) as nominated by [Weronika Łabaj](https://weronikalabaj.com/) 13 | * 2019 January: $50USD to [Black Girls Code](http://www.blackgirlscode.com) as nominated by [Weronika Łabaj](https://weronikalabaj.com/) 14 | * 2018 December: $50USD to [Planned Parenthood](https://www.plannedparenthood.org) as nominated by [Brad Wilson](https://twitter.com/BradWilson) as a thanks for the use of [xUnit](https://xunit.github.io/) 15 | 16 | 17 | ## Motivations 18 | 19 | Attempt to help organizations that are addressing the diversity problem in the technology industry. Further reading: 20 | 21 | * [The Ethics of Unpaid Labor and the OSS Community | Ashe Dryden](https://www.ashedryden.com/blog/the-ethics-of-unpaid-labor-and-the-oss-community) 22 | * [Deconstructing Privilege | Patricia Aas](https://vimeo.com/285097367) 23 | * [StackOverflow Developer Survey Results, 2018, Demographics](https://insights.stackoverflow.com/survey/2018/#demographics) 24 | -------------------------------------------------------------------------------- /src/Docs/MyLoggingWeaver.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using Fody; 4 | 5 | public class MyLoggingWeaver : 6 | BaseModuleWeaver 7 | { 8 | public override void Execute() 9 | { 10 | // Write a log entry with a specific MessageImportance 11 | WriteMessage("Message", MessageImportance.High); 12 | 13 | // Write a log entry with the MessageImportance.Low level 14 | WriteDebug("Message"); 15 | 16 | // Write a log entry with the MessageImportance.Normal level 17 | WriteInfo("Message"); 18 | 19 | // Write a warning 20 | WriteWarning("Message"); 21 | 22 | // Write an error 23 | WriteError("Message"); 24 | 25 | var type = ModuleDefinition.GetType("MyType"); 26 | var method = type.Methods.First(); 27 | 28 | // Write an error using the first SequencePoint 29 | // of a method for the line information 30 | WriteWarning("Message", method); 31 | 32 | // Write an error using the first SequencePoint 33 | // of a method for the line information 34 | WriteError("Message", method); 35 | 36 | var sequencePoint = method.DebugInformation.SequencePoints.First(); 37 | 38 | // Write an warning using a SequencePoint 39 | // for the line information 40 | WriteWarning("Message", sequencePoint); 41 | 42 | // Write an error using a SequencePoint 43 | // for the line information 44 | WriteError("Message", sequencePoint); 45 | } 46 | 47 | public override IEnumerable GetAssembliesForScanning() => Enumerable.Empty(); 48 | } -------------------------------------------------------------------------------- /src/FodyHome.sln: -------------------------------------------------------------------------------- 1 | Microsoft Visual Studio Solution File, Format Version 12.00 2 | # Visual Studio Version 16 3 | VisualStudioVersion = 16.0.29201.188 4 | MinimumVisualStudioVersion = 16.0.29201.188 5 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RepoSync", "RepoSync\RepoSync.csproj", "{51C59DFB-DCDF-4029-9AA1-92B3EF8EAF76}" 6 | EndProject 7 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Docs", "Docs\Docs.csproj", "{E5699F23-FF5C-4BD4-A8ED-CF9CC74075DD}" 8 | EndProject 9 | Global 10 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 11 | Debug|Any CPU = Debug|Any CPU 12 | Release|Any CPU = Release|Any CPU 13 | EndGlobalSection 14 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 15 | {51C59DFB-DCDF-4029-9AA1-92B3EF8EAF76}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 16 | {51C59DFB-DCDF-4029-9AA1-92B3EF8EAF76}.Debug|Any CPU.Build.0 = Debug|Any CPU 17 | {51C59DFB-DCDF-4029-9AA1-92B3EF8EAF76}.Release|Any CPU.ActiveCfg = Release|Any CPU 18 | {51C59DFB-DCDF-4029-9AA1-92B3EF8EAF76}.Release|Any CPU.Build.0 = Release|Any CPU 19 | {E5699F23-FF5C-4BD4-A8ED-CF9CC74075DD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 20 | {E5699F23-FF5C-4BD4-A8ED-CF9CC74075DD}.Debug|Any CPU.Build.0 = Debug|Any CPU 21 | {E5699F23-FF5C-4BD4-A8ED-CF9CC74075DD}.Release|Any CPU.ActiveCfg = Release|Any CPU 22 | {E5699F23-FF5C-4BD4-A8ED-CF9CC74075DD}.Release|Any CPU.Build.0 = Release|Any CPU 23 | EndGlobalSection 24 | GlobalSection(SolutionProperties) = preSolution 25 | HideSolutionNode = FALSE 26 | EndGlobalSection 27 | GlobalSection(ExtensibilityGlobals) = postSolution 28 | SolutionGuid = {F36FB31F-392B-47A7-AD2C-92693F097F66} 29 | EndGlobalSection 30 | EndGlobal 31 | -------------------------------------------------------------------------------- /BasicFodyAddin/SmokeTest/FodyWeavers.xsd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | Namespace to use for the injected type 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed. 20 | 21 | 22 | 23 | 24 | A comma-separated list of error codes that can be safely ignored in assembly verification. 25 | 26 | 27 | 28 | 29 | 'false' to turn off automatic generation of the XML Schema file. 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /pages/mdsource/addin-discovery.source.md: -------------------------------------------------------------------------------- 1 | # Addin Discovery 2 | 3 | Every Weaver must publish the location of it's binary ('WaverName.Fody.dll') at compile time as an MSBuild item, so Fody is able to locate it. This is achieved by providing a `.props` file with the NuGet package with the following default content: 4 | 5 | snippet: Weaver.props 6 | 7 | If the [FodyPackaging NuGet](addin-packaging.md#FodyPackaging-NuGet-Package) is used to create the addin package, this file is automatically added. 8 | 9 | However depending on requirements a custom file may be required. The important part is to provide an item named `WeaverFiles` that points to the location of the weaver assembly somewhere in the build chain. 10 | 11 | For example to replace the legacy `SolutionDir/Tool` or [in solution weaving](in-solution-weaving.md) conventions, add the `WeaverFiles` item to any project that needs to consume it: 12 | 13 | ```xml 14 | 15 | 17 | 18 | ``` 19 | 20 | 21 | ## Legacy strategies 22 | 23 | **Legacy strategies will no longer be supported in Fody version 4.0 and above** 24 | 25 | Legacy Weavers that are listed in the `FodyWeavers.xml` file, but don't expose the `WeaverFiles` MSBuild item, are located using a directory search. 26 | 27 | The following directories are searched for legacy Weavers 28 | 29 | * NuGet Package directories 30 | * SolutionDir/Tools 31 | * A project in the solution named 'Weavers'. See [in solution weaving](in-solution-weaving.md) 32 | 33 | Only the newest assembly of every found Weaver (as defined by Assembly.Version) is used. 34 | 35 | Since this can result in random results, depending on the actual content of the folders, avoid to use such legacy weavers, but ask the owner to update the weaver. -------------------------------------------------------------------------------- /pages/donations.md: -------------------------------------------------------------------------------- 1 | 7 | 8 | # Donations 9 | 10 | Every month the Fody project will donate a portion of funding raised to a charity or other cause. 11 | 12 | 13 | ## History 14 | 15 | * 2019 October: $50AUD to [Yalari](https://www.yalari.org/) 16 | * 2019 June: $50USD to [Diversify Tech](https://www.diversifytech.co/) as nominated by [Indu Alagarsamy](https://indu.dev/) 17 | * 2019 May: $50USD to [Women in Tech Podcast](http://podcast.womenintechshow.com/) by [Espree Devora](https://twitter.com/EspreeDevora) 18 | * 2019 May: $50USD to [Girl Develop It](https://www.girldevelopit.com/) 19 | * 2019 February: $50USD to [Ada Developers Academy](https://www.adadevelopersacademy.org) as nominated by [Weronika Łabaj](https://weronikalabaj.com/) 20 | * 2019 January: $50USD to [Black Girls Code](http://www.blackgirlscode.com) as nominated by [Weronika Łabaj](https://weronikalabaj.com/) 21 | * 2018 December: $50USD to [Planned Parenthood](https://www.plannedparenthood.org) as nominated by [Brad Wilson](https://twitter.com/BradWilson) as a thanks for the use of [xUnit](https://xunit.github.io/) 22 | 23 | 24 | ## Motivations 25 | 26 | Attempt to help organizations that are addressing the diversity problem in the technology industry. Further reading: 27 | 28 | * [The Ethics of Unpaid Labor and the OSS Community | Ashe Dryden](https://www.ashedryden.com/blog/the-ethics-of-unpaid-labor-and-the-oss-community) 29 | * [Deconstructing Privilege | Patricia Aas](https://vimeo.com/285097367) 30 | * [StackOverflow Developer Survey Results, 2018, Demographics](https://insights.stackoverflow.com/survey/2018/#demographics) 31 | -------------------------------------------------------------------------------- /pages/mdsource/addin-packaging.source.md: -------------------------------------------------------------------------------- 1 | # Addin packaging 2 | 3 | 4 | ## Convention 5 | 6 | The convention for Fody addin NuGet packages is as follows: 7 | 8 | 📁 build
9 |     AddinName.Fody.props
10 | 📁 lib
11 |    📁 net452
12 |        AddinName.dll
13 |        AddinName.xml
14 |    📁 netstandard2.0
15 |        AddinName.dll
16 |        AddinName.xml
17 | 📁 weaver
18 |     AddinName.Fody.dll
19 |     AddinName.Fody.xcf
20 | 21 | 22 | ### Convention Descriptions 23 | 24 | 25 | * `build/AddinName.Fody.props`: Facilitates [addin discovery](addin-discovery.md) via an [props file included by NuGet](https://docs.microsoft.com/en-us/nuget/create-packages/creating-a-package#including-msbuild-props-and-targets-in-a-package). 26 | * `lib`: Contains the [Lib/Reference project](addin-development.md#Lib/Reference-project) for all [supported target frameworks](https://docs.microsoft.com/en-us/nuget/create-packages/supporting-multiple-target-frameworks). 27 | * `weaver`: Contains the [Weaver Project](addin-development.md#Weaver-Project) assembly. Also contains the XCF file to [Supporting intellisense for FodyWeavers.xml](addin-development.md#Supporting-intellisense-for-FodyWeavers.xml). 28 | 29 | 30 | ## FodyPackaging NuGet Package 31 | 32 | The [FodyPackaging NuGet Package](https://www.nuget.org/packages/FodyPackaging/) simplifies following the above convention. 33 | 34 | 35 | ### MSBuild props and targets 36 | 37 | The below files are include as [MSBuild props and targets in a package](https://docs.microsoft.com/en-us/nuget/create-packages/creating-a-package#including-msbuild-props-and-targets-in-a-package). 38 | 39 | 40 | #### FodyPackaging.props 41 | 42 | snippet: FodyPackaging.props 43 | 44 | 45 | #### FodyPackaging.targets 46 | 47 | snippet: FodyPackaging.targets 48 | 49 | 50 | ### Weaver.props 51 | 52 | Included in the consuming package to facilitate [addin discovery](addin-discovery.md). 53 | 54 | snippet: Weaver.props -------------------------------------------------------------------------------- /pages/mdsource/usage.source.md: -------------------------------------------------------------------------------- 1 | # Usage 2 | 3 | Install using [NuGet](https://docs.microsoft.com/en-au/nuget/). See [Using the package manager console](https://docs.microsoft.com/en-au/nuget/tools/package-manager-console) for more info. 4 | 5 | Fody ships in two parts: 6 | 7 | 1. The core "engine" shipped in the [Fody NuGet package](https://www.nuget.org/packages/Fody/) 8 | 1. Any number of ["addins" or "weavers"](#addins-list) which are all shipped in their own NuGet packages. 9 | 10 | 11 | 12 | ## Install Fody 13 | 14 | Since NuGet always defaults to the oldest, and most buggy, version of any dependency it is important to do a [NuGet install](https://docs.microsoft.com/en-us/nuget/tools/ps-ref-install-package) of Fody after installing any weaver. 15 | 16 | ``` 17 | Install-Package Fody 18 | ``` 19 | 20 | [Subscribe to Fody](https://libraries.io/nuget/Fody) on [Libraries.io](https://libraries.io) to get notified of releases of Fody. 21 | 22 | 23 | ## Add the NuGet Package 24 | 25 | [Install](https://docs.microsoft.com/en-us/nuget/tools/ps-ref-install-package) the package in the project: 26 | 27 | ``` 28 | Install-Package WeaverName.Fody 29 | ``` 30 | 31 | e.g. 32 | 33 | ``` 34 | Install-Package Virtuosity.Fody 35 | ``` 36 | 37 | 38 | ## Adding Fody to a project that generates a NuGet package 39 | 40 | When Fody is added to a project that generates a NuGet package, the produced package will have a dependency on Fody. If this dependency needs to be removed from the generated .nupkg file, then, in the consuming .cproj project file, replace 41 | 42 | ```xml 43 | 44 | ``` 45 | 46 | with 47 | 48 | ```xml 49 | 50 | all 51 | 52 | ``` 53 | 54 | 55 | ## Add FodyWeavers.xml 56 | 57 | To indicate what weavers run and in what order a `FodyWeavers.xml` file is used at the project level. It needs to be added manually. It takes the following form: 58 | 59 | 60 | ```xml 61 | 62 | 63 | 64 | ``` 65 | 66 | e.g. 67 | 68 | ```xml 69 | 70 | 71 | 72 | ``` 73 | 74 | See [Configuration](configuration.md) for additional options. -------------------------------------------------------------------------------- /pages/mdsource/common-errors.source.md: -------------------------------------------------------------------------------- 1 | # Common Errors 2 | 3 | 4 | ## Building from a network share 5 | 6 | Building from a network share will result in the following exception: 7 | 8 | ``` 9 | Could not load file or assembly 'file:///S:\a\b\c\d.dll' or one of its dependencies. 10 | The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG)) 11 | ``` 12 | 13 | This is due to the security restriction put in place by MSBuild. 14 | 15 | Work around this problem by adding `` to the `MSBuild.exe.config` file of the build machine. 16 | 17 | It is theoretically possible for Fody to work around this problem by copying files locally before loading them. However considering the negative effects on build time due to decreased IO building from a network share is not a recommended practice. As such Fody will not be supporting this approach. 18 | 19 | 20 | ## Task could not be loaded 21 | 22 | If the below error occurs it is one of two problems: 23 | 24 | ``` 25 | error MSB4036: The "Fody.WeavingTask" task was not found... 26 | ``` 27 | 28 | 29 | ### Visual Studio is being difficult 30 | 31 | For a small number of users Visual Studio refuses to pick up the build task. The only workaround is to restart Visual Studio. 32 | 33 | Unfortunately there is nothing that can be done to fix this in Fody as it occurs before any interaction with the Fody implementation. 34 | 35 | 36 | ### Invalid symbols in the solution path 37 | 38 | There is a bug in MSBuild that causes it to inject incorrect path variables when there certain symbols in the directory path containing the solution. 39 | 40 | So for example the solution is located at: 41 | 42 | ``` 43 | G:\Code\@MyClassLibrary\MyClassLibrary.sln 44 | ``` 45 | 46 | MSBuild will incorrectly substitute `$(SolutionDir)` with: 47 | 48 | ``` 49 | G:\Code\%40MyClassLibrary\ 50 | ``` 51 | 52 | Instead of: 53 | 54 | ``` 55 | G:\Code\@MyClassLibrary\ 56 | ``` 57 | 58 | There is nothing that can be done to fix this in Fody. If this error occurs the only option is to remove the symbols from the solution path. 59 | 60 | 61 | ## Edit and continue 62 | 63 | Edit and continue is not supported. There is no extension point to re-weave an assembly after the edit part. -------------------------------------------------------------------------------- /pages/mdsource/backers.source.md: -------------------------------------------------------------------------------- 1 | # Backers 2 | 3 | Below is a list of the people and organizations that have made significant contributions. Consider joining them in supporting open source by [becoming a Patron of Fody](https://opencollective.com/fody/order/3059). 4 | 5 | 6 | ## Patrons 7 | 8 | 9 | 10 | All patrons: https://opencollective.com/fody/members/all.json 11 | 12 | * Adam Hill | [Open Collective](https://opencollective.com/adamhill) 13 | * Intreba | [Open Collective](https://github.com/Intreba) 14 | 15 | 16 | ## Significant contributors 17 | 18 | * Cameron MacFarland | [GitHub](https://github.com/distantcam) | [OpenCollective](https://opencollective.com/distantcam) 19 | * Damian Reeves | [GitHub](https://github.com/DamianReeves) 20 | * Geert van Horrik [GitHub](https://github.com/GeertvanHorrik) | [OpenCollective](https://opencollective.com/geertvanhorrik) 21 | * Lucas Trzesniewski | [GitHub](https://github.com/ltrzesniewski) | [OpenCollective](https://opencollective.com/lucas-trzesniewski) 22 | * Simon Cropp | [GitHub](https://github.com/simoncropp) | [OpenCollective](https://opencollective.com/simoncropp) 23 | * Tom Englert | [GitHub](https://github.com/tom-englert) | [OpenCollective](https://opencollective.com/thomas-englert) 24 | 25 | 26 | ## Once off backers 27 | 28 | 29 | 30 | * Jan-Pieter Zoutewelle | [GitHub](https://github.com/janpieterz) | [OpenCollective](https://opencollective.com/intreba-bv) 31 | * John Bayly | [OpenCollective](https://opencollective.com/john-bayly) 32 | * Kirk Woll | [OpenCollective](https://opencollective.com/kirk-woll) | [GitHub](https://github.com/kswoll) 33 | * Krittayot Tech | [OpenCollective](https://opencollective.com/anonymous374) 34 | * Anonymous1147 | [Open Collective](https://opencollective.com/anonymous1147) 35 | * Euug3576 | [OpenCollective](https://opencollective.com/euug3576) 36 | * Jakub Suchy | [OpenCollective](https://opencollective.com/jakub-suchy) | [GitHub](https://github.com/jakubsuchybio) 37 | * Miha Markic | [OpenCollective](https://opencollective.com/mihamarkic) | [GitHub](https://github.com/MihaMarkic) 38 | * Peter Major | [OpenCollective](https://opencollective.com/peter-major) | [GitHub](https://github.com/petermajor) 39 | -------------------------------------------------------------------------------- /pages/addin-discovery.md: -------------------------------------------------------------------------------- 1 | 7 | 8 | # Addin Discovery 9 | 10 | Every Weaver must publish the location of it's binary ('WaverName.Fody.dll') at compile time as an MSBuild item, so Fody is able to locate it. This is achieved by providing a `.props` file with the NuGet package with the following default content: 11 | 12 | 13 | 14 | ```props 15 | 16 | 17 | 18 | 19 | 20 | 21 | ``` 22 | anchor 23 | 24 | 25 | If the [FodyPackaging NuGet](addin-packaging.md#FodyPackaging-NuGet-Package) is used to create the addin package, this file is automatically added. 26 | 27 | However depending on requirements a custom file may be required. The important part is to provide an item named `WeaverFiles` that points to the location of the weaver assembly somewhere in the build chain. 28 | 29 | For example to replace the legacy `SolutionDir/Tool` or [in solution weaving](in-solution-weaving.md) conventions, add the `WeaverFiles` item to any project that needs to consume it: 30 | 31 | ```xml 32 | 33 | 35 | 36 | ``` 37 | 38 | 39 | ## Legacy strategies 40 | 41 | **Legacy strategies will no longer be supported in Fody version 4.0 and above** 42 | 43 | Legacy Weavers that are listed in the `FodyWeavers.xml` file, but don't expose the `WeaverFiles` MSBuild item, are located using a directory search. 44 | 45 | The following directories are searched for legacy Weavers 46 | 47 | * NuGet Package directories 48 | * SolutionDir/Tools 49 | * A project in the solution named 'Weavers'. See [in solution weaving](in-solution-weaving.md) 50 | 51 | Only the newest assembly of every found Weaver (as defined by Assembly.Version) is used. 52 | 53 | Since this can result in random results, depending on the actual content of the folders, avoid to use such legacy weavers, but ask the owner to update the weaver. 54 | -------------------------------------------------------------------------------- /images/g-research.svg: -------------------------------------------------------------------------------- 1 | g-research -------------------------------------------------------------------------------- /pages/usage.md: -------------------------------------------------------------------------------- 1 | 7 | 8 | # Usage 9 | 10 | Install using [NuGet](https://docs.microsoft.com/en-au/nuget/). See [Using the package manager console](https://docs.microsoft.com/en-au/nuget/tools/package-manager-console) for more info. 11 | 12 | Fody ships in two parts: 13 | 14 | 1. The core "engine" shipped in the [Fody NuGet package](https://www.nuget.org/packages/Fody/) 15 | 1. Any number of ["addins" or "weavers"](#addins-list) which are all shipped in their own NuGet packages. 16 | 17 | 18 | 19 | ## Install Fody 20 | 21 | Since NuGet always defaults to the oldest, and most buggy, version of any dependency it is important to do a [NuGet install](https://docs.microsoft.com/en-us/nuget/tools/ps-ref-install-package) of Fody after installing any weaver. 22 | 23 | ``` 24 | Install-Package Fody 25 | ``` 26 | 27 | [Subscribe to Fody](https://libraries.io/nuget/Fody) on [Libraries.io](https://libraries.io) to get notified of releases of Fody. 28 | 29 | 30 | ## Add the NuGet Package 31 | 32 | [Install](https://docs.microsoft.com/en-us/nuget/tools/ps-ref-install-package) the package in the project: 33 | 34 | ``` 35 | Install-Package WeaverName.Fody 36 | ``` 37 | 38 | e.g. 39 | 40 | ``` 41 | Install-Package Virtuosity.Fody 42 | ``` 43 | 44 | 45 | ## Adding Fody to a project that generates a NuGet package 46 | 47 | When Fody is added to a project that generates a NuGet package, the produced package will have a dependency on Fody. If this dependency needs to be removed from the generated .nupkg file, then, in the consuming .cproj project file, replace 48 | 49 | ```xml 50 | 51 | ``` 52 | 53 | with 54 | 55 | ```xml 56 | 57 | all 58 | 59 | ``` 60 | 61 | 62 | ## Add FodyWeavers.xml 63 | 64 | To indicate what weavers run and in what order a `FodyWeavers.xml` file is used at the project level. It needs to be added manually. It takes the following form: 65 | 66 | 67 | ```xml 68 | 69 | 70 | 71 | ``` 72 | 73 | e.g. 74 | 75 | ```xml 76 | 77 | 78 | 79 | ``` 80 | 81 | See [Configuration](configuration.md) for additional options. 82 | -------------------------------------------------------------------------------- /pages/common-errors.md: -------------------------------------------------------------------------------- 1 | 7 | 8 | # Common Errors 9 | 10 | 11 | ## Building from a network share 12 | 13 | Building from a network share will result in the following exception: 14 | 15 | ``` 16 | Could not load file or assembly 'file:///S:\a\b\c\d.dll' or one of its dependencies. 17 | The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG)) 18 | ``` 19 | 20 | This is due to the security restriction put in place by MSBuild. 21 | 22 | Work around this problem by adding `` to the `MSBuild.exe.config` file of the build machine. 23 | 24 | It is theoretically possible for Fody to work around this problem by copying files locally before loading them. However considering the negative effects on build time due to decreased IO building from a network share is not a recommended practice. As such Fody will not be supporting this approach. 25 | 26 | 27 | ## Task could not be loaded 28 | 29 | If the below error occurs it is one of two problems: 30 | 31 | ``` 32 | error MSB4036: The "Fody.WeavingTask" task was not found... 33 | ``` 34 | 35 | 36 | ### Visual Studio is being difficult 37 | 38 | For a small number of users Visual Studio refuses to pick up the build task. The only workaround is to restart Visual Studio. 39 | 40 | Unfortunately there is nothing that can be done to fix this in Fody as it occurs before any interaction with the Fody implementation. 41 | 42 | 43 | ### Invalid symbols in the solution path 44 | 45 | There is a bug in MSBuild that causes it to inject incorrect path variables when there certain symbols in the directory path containing the solution. 46 | 47 | So for example the solution is located at: 48 | 49 | ``` 50 | G:\Code\@MyClassLibrary\MyClassLibrary.sln 51 | ``` 52 | 53 | MSBuild will incorrectly substitute `$(SolutionDir)` with: 54 | 55 | ``` 56 | G:\Code\%40MyClassLibrary\ 57 | ``` 58 | 59 | Instead of: 60 | 61 | ``` 62 | G:\Code\@MyClassLibrary\ 63 | ``` 64 | 65 | There is nothing that can be done to fix this in Fody. If this error occurs the only option is to remove the symbols from the solution path. 66 | 67 | 68 | ## Edit and continue 69 | 70 | Edit and continue is not supported. There is no extension point to re-weave an assembly after the edit part. 71 | -------------------------------------------------------------------------------- /pages/backers.md: -------------------------------------------------------------------------------- 1 | 7 | 8 | # Backers 9 | 10 | Below is a list of the people and organizations that have made significant contributions. Consider joining them in supporting open source by [becoming a Patron of Fody](https://opencollective.com/fody/order/3059). 11 | 12 | 13 | ## Patrons 14 | 15 | 16 | 17 | All patrons: https://opencollective.com/fody/members/all.json 18 | 19 | * Adam Hill | [Open Collective](https://opencollective.com/adamhill) 20 | * Intreba | [Open Collective](https://github.com/Intreba) 21 | 22 | 23 | ## Significant contributors 24 | 25 | * Cameron MacFarland | [GitHub](https://github.com/distantcam) | [OpenCollective](https://opencollective.com/distantcam) 26 | * Damian Reeves | [GitHub](https://github.com/DamianReeves) 27 | * Geert van Horrik [GitHub](https://github.com/GeertvanHorrik) | [OpenCollective](https://opencollective.com/geertvanhorrik) 28 | * Lucas Trzesniewski | [GitHub](https://github.com/ltrzesniewski) | [OpenCollective](https://opencollective.com/lucas-trzesniewski) 29 | * Simon Cropp | [GitHub](https://github.com/simoncropp) | [OpenCollective](https://opencollective.com/simoncropp) 30 | * Tom Englert | [GitHub](https://github.com/tom-englert) | [OpenCollective](https://opencollective.com/thomas-englert) 31 | 32 | 33 | ## Once off backers 34 | 35 | 36 | 37 | * Jan-Pieter Zoutewelle | [GitHub](https://github.com/janpieterz) | [OpenCollective](https://opencollective.com/intreba-bv) 38 | * John Bayly | [OpenCollective](https://opencollective.com/john-bayly) 39 | * Kirk Woll | [OpenCollective](https://opencollective.com/kirk-woll) | [GitHub](https://github.com/kswoll) 40 | * Krittayot Tech | [OpenCollective](https://opencollective.com/anonymous374) 41 | * Anonymous1147 | [Open Collective](https://opencollective.com/anonymous1147) 42 | * Euug3576 | [OpenCollective](https://opencollective.com/euug3576) 43 | * Jakub Suchy | [OpenCollective](https://opencollective.com/jakub-suchy) | [GitHub](https://github.com/jakubsuchybio) 44 | * Miha Markic | [OpenCollective](https://opencollective.com/mihamarkic) | [GitHub](https://github.com/MihaMarkic) 45 | * Peter Major | [OpenCollective](https://opencollective.com/peter-major) | [GitHub](https://github.com/petermajor) 46 | -------------------------------------------------------------------------------- /pages/mdsource/in-solution-weaving.source.md: -------------------------------------------------------------------------------- 1 | # In solution weaving 2 | 3 | 4 | ## Introduction 5 | 6 | Sometimes it is necessary to have weaving code specific to a solution. In this case it is desirable to have that code exist in the same solution it is editing. 7 | 8 | - _Note: Starting with Fody 4.0 the implicit lookup of weavers by naming conventions is no longer supported. 9 | Follow the instructions below on to migrate projects._ 10 | 11 | 12 | ## Weaving inside a solution 13 | 14 | Fody will [look for weavers by examining the `WeaverFiles` items](addin-discovery.md) of the project. 15 | 16 | 17 | To enable in-solution weaving: 18 | 19 | 1. Add a project named e.g. 'Weavers' to the solution. 20 | 1. Add a class named `ModuleWeaver` to the project. See [ModuleWeaver](addin-development.md#weaver-project). 21 | _Note: The `ModuleWeaver` is the default name for the weaver class. It is also possible to use multiple weavers with different class names by specifying their class names in the `WeaverClassNames` attribute._ 22 | 1. Change the [solution build order](https://docs.microsoft.com/en-au/visualstudio/ide/how-to-create-and-remove-project-dependencies) so the 'Weavers' project is built before the projects consuming it. _Note: Do not add a project reference to the weaver_ 23 | 1. If a weaver class is explicitly specified in the `WeaverClassNames` attribute, Fody expects the configuration entry in the `FodyWeavers.xml` file to be named like the class. For example, if the class name is `NamedWeaver`: 24 | 25 | ```xml 26 | 27 | 28 | 29 | ``` 30 | 31 | The [FodyAddinSamples](https://github.com/Fody/FodyAddinSamples/) repository provides examples of this. 32 | 33 | * Weavers project: https://github.com/Fody/FodyAddinSamples/tree/master/Weavers 34 | * The FodyWeavers.xml that includes those weavers: https://github.com/Fody/FodyAddinSamples/blob/master/Samples/FodyWeavers.xml 35 | * Test that verifies the weaving has occurred https://github.com/Fody/FodyAddinSamples/blob/master/Samples/InSolutionSample.cs 36 | 37 | To **optionally** use a custom named weaver file for in solution weaving, add an entry to the project file: 38 | 39 | ```xml 40 | 41 | 44 | 45 | ``` 46 | 47 | The `WeaverClassNames` entry is optional. If not specified, Fody will look for a class named `ModuleWeaver`. 48 | If the weaver assembly contains more than one weaver, specify the class names of all the weavers to use in the target project. -------------------------------------------------------------------------------- /pages/mdsource/readme.source.md: -------------------------------------------------------------------------------- 1 | ## Documentation and Further Learning 2 | 3 | * [Licensing and patron FAQ](https://github.com/Fody/Home/tree/master/pages/licensing-patron-faq.md)
4 | **It is expected that all developers using Fody [become a Patron on OpenCollective](https://opencollective.com/fody/order/3059).** See [Licensing/Patron FAQ](https://github.com/Fody/Home/tree/master/pages/licensing-patron-faq.md) for more information. 5 | * [Usage](https://github.com/Fody/Home/tree/master/pages/usage.md)
6 | Introduction to using Fody. 7 | * [Configuration](https://github.com/Fody/Home/tree/master/pages/configuration.md)
8 | All configuration options for Fody. 9 | * [Addin discovery](https://github.com/Fody/Home/tree/master/pages/addin-discovery.md)
10 | How addins are resolved. 11 | * [List of Fody weavers/addins](https://github.com/Fody/Home/tree/master/pages/addins.md)
12 | * [FodyAddinSamples](https://github.com/Fody/FodyAddinSamples)
13 | A GitHub repo that contains a working sample of every Fody addin. 14 | * [Common errors](https://github.com/Fody/Home/tree/master/pages/common-errors.md) 15 | * [In solution weaving](https://github.com/Fody/Home/tree/master/pages/in-solution-weaving.md)
16 | Writing an addin that manipulates IL within the same solution. 17 | * [ProcessedByFody class](https://github.com/Fody/Home/tree/master/pages/processedbyfody-class.md)
18 | Marker class added to target assemblies for diagnostic purposes. 19 | * [Strong naming](https://github.com/Fody/Home/tree/master/pages/strong-naming.md) 20 | * [Supported runtimes and IDE](https://github.com/Fody/Home/tree/master/pages/supported-runtimes-and-ide.md) 21 | * [Addin development](https://github.com/Fody/Home/tree/master/pages/addin-development.md)
22 | Building a new Fody addin. 23 | * [Addin packaging](https://github.com/Fody/Home/tree/master/pages/addin-packaging.md)
24 | Packaging and deployment of Fody weavers. 25 | * [BasicFodyAddin](/BasicFodyAddin)
26 | A project meant to illustrate how to build an addin. 27 | * [Fody Project Configuration Manager](https://github.com/tom-englert/ProjectConfigurationManager/wiki/6.-Fody)
28 | Provides an interactive tool that can support configuring weavers, which is especially helpful in solutions with many projects. 29 | * [Backers tracking/info](https://github.com/Fody/Home/tree/master/pages/backers.md) 30 | * [Donations](https://github.com/Fody/Home/tree/master/pages/donations.md)
31 | Every month the Fody project will donate a portion of funding raised to a charity or other cause. 32 | * [Version 5 upgrade guide](https://github.com/Fody/Home/tree/master/pages/upgradeGuideV5.md) -------------------------------------------------------------------------------- /pages/in-solution-weaving.md: -------------------------------------------------------------------------------- 1 | 7 | 8 | # In solution weaving 9 | 10 | 11 | ## Introduction 12 | 13 | Sometimes it is necessary to have weaving code specific to a solution. In this case it is desirable to have that code exist in the same solution it is editing. 14 | 15 | - _Note: Starting with Fody 4.0 the implicit lookup of weavers by naming conventions is no longer supported. 16 | Follow the instructions below on to migrate projects._ 17 | 18 | 19 | ## Weaving inside a solution 20 | 21 | Fody will [look for weavers by examining the `WeaverFiles` items](addin-discovery.md) of the project. 22 | 23 | 24 | To enable in-solution weaving: 25 | 26 | 1. Add a project named e.g. 'Weavers' to the solution. 27 | 1. Add a class named `ModuleWeaver` to the project. See [ModuleWeaver](addin-development.md#weaver-project). 28 | _Note: The `ModuleWeaver` is the default name for the weaver class. It is also possible to use multiple weavers with different class names by specifying their class names in the `WeaverClassNames` attribute._ 29 | 1. Change the [solution build order](https://docs.microsoft.com/en-au/visualstudio/ide/how-to-create-and-remove-project-dependencies) so the 'Weavers' project is built before the projects consuming it. _Note: Do not add a project reference to the weaver_ 30 | 1. If a weaver class is explicitly specified in the `WeaverClassNames` attribute, Fody expects the configuration entry in the `FodyWeavers.xml` file to be named like the class. For example, if the class name is `NamedWeaver`: 31 | 32 | ```xml 33 | 34 | 35 | 36 | ``` 37 | 38 | The [FodyAddinSamples](https://github.com/Fody/FodyAddinSamples/) repository provides examples of this. 39 | 40 | * Weavers project: https://github.com/Fody/FodyAddinSamples/tree/master/Weavers 41 | * The FodyWeavers.xml that includes those weavers: https://github.com/Fody/FodyAddinSamples/blob/master/Samples/FodyWeavers.xml 42 | * Test that verifies the weaving has occurred https://github.com/Fody/FodyAddinSamples/blob/master/Samples/InSolutionSample.cs 43 | 44 | To **optionally** use a custom named weaver file for in solution weaving, add an entry to the project file: 45 | 46 | ```xml 47 | 48 | 51 | 52 | ``` 53 | 54 | The `WeaverClassNames` entry is optional. If not specified, Fody will look for a class named `ModuleWeaver`. 55 | If the weaver assembly contains more than one weaver, specify the class names of all the weavers to use in the target project. 56 | -------------------------------------------------------------------------------- /src/RepoSync/Source/.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig: http://EditorConfig.org 2 | 3 | # top-most EditorConfig file 4 | root = true 5 | 6 | [*] 7 | indent_style = space:error 8 | 9 | [*.cs] 10 | indent_size = 4:error 11 | charset = utf-8-bom:error 12 | 13 | # Sort using and Import directives with System.* appearing first 14 | dotnet_sort_system_directives_first = true:error 15 | 16 | # Avoid "this." and "Me." if not necessary 17 | dotnet_style_qualification_for_field = false:error 18 | dotnet_style_qualification_for_property = false:error 19 | dotnet_style_qualification_for_method = false:error 20 | dotnet_style_qualification_for_event = false:error 21 | 22 | # Use language keywords instead of framework type names for type references 23 | dotnet_style_predefined_type_for_locals_parameters_members = true:error 24 | dotnet_style_predefined_type_for_member_access = true:error 25 | 26 | # Suggest more modern language features when available 27 | dotnet_style_object_initializer = true:suggestion 28 | dotnet_style_collection_initializer = true:suggestion 29 | dotnet_style_coalesce_expression = false:suggestion 30 | dotnet_style_null_propagation = true:suggestion 31 | dotnet_style_explicit_tuple_names = true:suggestion 32 | 33 | # Prefer "var" everywhere 34 | csharp_style_var_for_built_in_types = true:error 35 | csharp_style_var_when_type_is_apparent = true:error 36 | csharp_style_var_elsewhere = true:error 37 | 38 | # Prefer method-like constructs to have a block body 39 | csharp_style_expression_bodied_methods = false:none 40 | csharp_style_expression_bodied_constructors = false:none 41 | csharp_style_expression_bodied_operators = false:none 42 | 43 | # Prefer property-like constructs to have an expression-body 44 | csharp_style_expression_bodied_properties = true:suggestion 45 | csharp_style_expression_bodied_indexers = true:suggestion 46 | csharp_style_expression_bodied_accessors = true:none 47 | 48 | # Suggest more modern language features when available 49 | csharp_style_pattern_matching_over_is_with_cast_check = true:error 50 | csharp_style_pattern_matching_over_as_with_null_check = true:error 51 | csharp_style_inlined_variable_declaration = true:suggestion 52 | csharp_style_throw_expression = true:suggestion 53 | csharp_style_conditional_delegate_call = true:suggestion 54 | 55 | # Newline settings 56 | #csharp_new_line_before_open_brace = all:error 57 | csharp_new_line_before_else = true:error 58 | csharp_new_line_before_catch = true:error 59 | csharp_new_line_before_finally = true:error 60 | csharp_new_line_before_members_in_object_initializers = true:error 61 | csharp_new_line_before_members_in_anonymous_types = true:error 62 | 63 | #braces 64 | #csharp_prefer_braces = true:error 65 | 66 | # msbuild 67 | [*.{csproj,targets,props}] 68 | indent_size = 2 69 | 70 | # Xml files 71 | [*.{xml,config,nuspec,resx,vsixmanifest}] 72 | indent_size = 2 73 | resharper_xml_wrap_tags_and_pi = true:error 74 | 75 | # JSON files 76 | [*.json] 77 | indent_size = 2 78 | -------------------------------------------------------------------------------- /pages/readme.md: -------------------------------------------------------------------------------- 1 | 7 | 8 | ## Documentation and Further Learning 9 | 10 | * [Licensing and patron FAQ](https://github.com/Fody/Home/tree/master/pages/licensing-patron-faq.md)
11 | **It is expected that all developers using Fody [become a Patron on OpenCollective](https://opencollective.com/fody/order/3059).** See [Licensing/Patron FAQ](https://github.com/Fody/Home/tree/master/pages/licensing-patron-faq.md) for more information. 12 | * [Usage](https://github.com/Fody/Home/tree/master/pages/usage.md)
13 | Introduction to using Fody. 14 | * [Configuration](https://github.com/Fody/Home/tree/master/pages/configuration.md)
15 | All configuration options for Fody. 16 | * [Addin discovery](https://github.com/Fody/Home/tree/master/pages/addin-discovery.md)
17 | How addins are resolved. 18 | * [List of Fody weavers/addins](https://github.com/Fody/Home/tree/master/pages/addins.md)
19 | * [FodyAddinSamples](https://github.com/Fody/FodyAddinSamples)
20 | A GitHub repo that contains a working sample of every Fody addin. 21 | * [Common errors](https://github.com/Fody/Home/tree/master/pages/common-errors.md) 22 | * [In solution weaving](https://github.com/Fody/Home/tree/master/pages/in-solution-weaving.md)
23 | Writing an addin that manipulates IL within the same solution. 24 | * [ProcessedByFody class](https://github.com/Fody/Home/tree/master/pages/processedbyfody-class.md)
25 | Marker class added to target assemblies for diagnostic purposes. 26 | * [Strong naming](https://github.com/Fody/Home/tree/master/pages/strong-naming.md) 27 | * [Supported runtimes and IDE](https://github.com/Fody/Home/tree/master/pages/supported-runtimes-and-ide.md) 28 | * [Addin development](https://github.com/Fody/Home/tree/master/pages/addin-development.md)
29 | Building a new Fody addin. 30 | * [Addin packaging](https://github.com/Fody/Home/tree/master/pages/addin-packaging.md)
31 | Packaging and deployment of Fody weavers. 32 | * [BasicFodyAddin](/BasicFodyAddin)
33 | A project meant to illustrate how to build an addin. 34 | * [Fody Project Configuration Manager](https://github.com/tom-englert/ProjectConfigurationManager/wiki/6.-Fody)
35 | Provides an interactive tool that can support configuring weavers, which is especially helpful in solutions with many projects. 36 | * [Backers tracking/info](https://github.com/Fody/Home/tree/master/pages/backers.md) 37 | * [Donations](https://github.com/Fody/Home/tree/master/pages/donations.md)
38 | Every month the Fody project will donate a portion of funding raised to a charity or other cause. 39 | * [Version 5 upgrade guide](https://github.com/Fody/Home/tree/master/pages/upgradeGuideV5.md) 40 | -------------------------------------------------------------------------------- /pages/mdsource/supported-runtimes-and-ide.source.md: -------------------------------------------------------------------------------- 1 | # Supported .net runtimes and IDE 2 | 3 | 4 | ## Visual Studio support 5 | 6 | Fody requires one of the following at build time: 7 | 8 | * [MSBuild 16](https://docs.microsoft.com/en-us/visualstudio/msbuild/msbuild?view=vs-2019) which ships with Visual Studio 2019. 9 | * [dotnet core SDK 2.2.105](https://dotnet.microsoft.com/download) (or higher) to work with [dotnet build](https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-build). 10 | 11 | 12 | ## Project formats 13 | 14 | The following are not supported 15 | 16 | * Projects using the [project.json](https://docs.microsoft.com/en-us/nuget/schema/project-json). 17 | * Projects using the xproj. 18 | 19 | To tell the difference between the old and new csproj formats. 20 | 21 | The old format starts with: 22 | 23 | ``` 24 | 25 | ``` 26 | 27 | The new format starts with: 28 | 29 | ``` 30 | 31 | ``` 32 | 33 | For all these scenarios is it instead recommended to move to the new SDK style projects. 34 | 35 | References 36 | 37 | * [Bye-Bye Project.json and .xproj and welcome back .csproj](http://www.talkingdotnet.com/bye-bye-project-json-xproj-welcome-back-csproj/) 38 | * [Project.json to MSBuild conversion guide](http://www.natemcmaster.com/blog/2017/01/19/project-json-to-csproj/) 39 | * [Migrate from project.json to new SDK style projects](https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-migrate) 40 | 41 | 42 | ## Target framework 43 | 44 | * Classic .NET: See *Support ended* in [NET Framework version history](https://en.wikipedia.org/wiki/.NET_Framework_version_history#Overview). i.e only 4.5.2 and above is supported. 45 | * .NET core: Follows [.NET Core Support Policy](https://www.microsoft.com/net/core/support). 46 | 47 | No explicit code is in place to check for non supported versions, and throw an error. As such earlier versions of .net may work as a side effect. It's all up to the individual weavers used and what version they are able to support. 48 | 49 | Any bugs found must be reproduced in a supported version. 50 | 51 | Downstream weavers are recommended to follow the above guidelines. 52 | 53 | 54 | ### Reasons 55 | 56 | While it may seam trivial to "implement support for earlier versions of .net" the long term support implications are too costly. For example to support earlier versions of .net require 57 | 58 | * Custom VMs to verify problems. 59 | * Added complexity to setting up build environment. 60 | * Bugs in unsupported versions in .NET may be manifest as bugs in Fody. 61 | 62 | 63 | ## Implications if using using Fody on project 64 | 65 | Fody provides the build integration for the weavers. The runtime that the project may target only depends on the weaver(s) being used; see the documentation of the individual weavers to know what frameworks are supported. 66 | 67 | The target framework(s) supported by a weaver is up to the designer of the individual weaver. Since extending the range of supported frameworks might introduce extra overhead, not all possible framework versions might be actively supported. 68 | -------------------------------------------------------------------------------- /src/RepoSync/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | using GitHubSync; 4 | using Octokit; 5 | 6 | class Program 7 | { 8 | static Task Main() 9 | { 10 | var githubToken = Environment.GetEnvironmentVariable("Octokit_OAuthToken"); 11 | 12 | var credentials = new Credentials(githubToken); 13 | 14 | var sync = new RepoSync( 15 | log: Console.WriteLine, 16 | defaultCredentials: credentials, 17 | syncMode: SyncMode.ExcludeAllByDefault); 18 | 19 | sync.AddSourceRepository( 20 | owner: "Fody", 21 | repository: "Home", 22 | branch: "master"); 23 | 24 | //sync.AddSourceItem(TreeEntryTargetType.Blob, "RepoSync/appveyor.yml", "appveyor.yml"); 25 | sync.AddSourceItem(TreeEntryTargetType.Blob, "src/RepoSync/Source/.editorconfig", ".editorconfig"); 26 | sync.AddSourceItem(TreeEntryTargetType.Blob, "src/RepoSync/Source/FUNDING.yml", ".github/FUNDING.yml"); 27 | sync.AddSourceItem(TreeEntryTargetType.Blob, "src/RepoSync/Source/workflows/on-push-do-doco.yml", ".github/workflows/on-push-do-doco.yml"); 28 | sync.AddSourceItem(TreeEntryTargetType.Blob, "src/RepoSync/Source/workflows/on-tag-do-release.yml", ".github/workflows/on-tag-do-release.yml"); 29 | sync.AddTargetRepository("Fody", "Fody", "master"); 30 | sync.AddTargetRepository("Fody", "Anotar", "master"); 31 | sync.AddTargetRepository("Fody", "AsyncErrorHandler", "master"); 32 | sync.AddTargetRepository("Fody", "Caseless", "master"); 33 | sync.AddTargetRepository("Fody", "ConfigureAwait", "master"); 34 | //sync.AddTargetRepository("Fody", "Costura", "master"); 35 | sync.AddTargetRepository("Fody", "EmptyConstructor", "master"); 36 | sync.AddTargetRepository("Fody", "Equals", "master"); 37 | sync.AddTargetRepository("Fody", "ExtraConstraints", "master"); 38 | sync.AddTargetRepository("Fody", "InfoOf", "master"); 39 | sync.AddTargetRepository("Fody", "Ionad", "master"); 40 | sync.AddTargetRepository("Fody", "Janitor", "master"); 41 | sync.AddTargetRepository("Fody", "LoadAssembliesOnStartup", "master"); 42 | sync.AddTargetRepository("Fody", "MethodDecorator", "master"); 43 | sync.AddTargetRepository("Fody", "MethodTimer", "master"); 44 | sync.AddTargetRepository("Fody", "ModuleInit", "master"); 45 | sync.AddTargetRepository("Fody", "NullGuard", "master"); 46 | sync.AddTargetRepository("Fody", "Obsolete", "master"); 47 | sync.AddTargetRepository("Fody", "PropertyChanged", "master"); 48 | sync.AddTargetRepository("Fody", "PropertyChanging", "master"); 49 | sync.AddTargetRepository("Fody", "Publicize", "master"); 50 | sync.AddTargetRepository("Fody", "Resourcer", "master"); 51 | sync.AddTargetRepository("Fody", "Scalpel", "master"); 52 | sync.AddTargetRepository("Fody", "ToString", "master"); 53 | sync.AddTargetRepository("Fody", "Validar", "master"); 54 | sync.AddTargetRepository("Fody", "Virtuosity", "master"); 55 | sync.AddTargetRepository("Fody", "Visualize", "master"); 56 | 57 | return sync.Sync(SyncOutput.MergePullRequest); 58 | } 59 | } -------------------------------------------------------------------------------- /pages/mdsource/upgradeGuideV5.source.md: -------------------------------------------------------------------------------- 1 | # Version 5 upgrade guide 2 | 3 | 4 | ## Consumers 5 | 6 | Fody now requires MSBuild16. 7 | 8 | This means any tool chain being used needs to support MSBuild16. For example: 9 | 10 | * Visual Studio 19. 11 | * [dotnet core SDK 2.2](https://dotnet.microsoft.com/download/dotnet-core/2.2). 12 | * JetBrains Rider 2018.3.4. 13 | 14 | To ensure all consumers are using the correct build tooling, ensure the `.sln` file starts with: 15 | 16 | ``` 17 | Microsoft Visual Studio Solution File, Format Version 12.00 18 | # Visual Studio Version 16 19 | VisualStudioVersion = 16.0.28721.148 20 | MinimumVisualStudioVersion = 16.0.28721.148 21 | ``` 22 | 23 | 24 | ### Build server 25 | 26 | To use MSBuild install [Build Tools for Visual Studio 2019](https://visualstudio.microsoft.com/downloads/#vstool-2019). To use dotnet build install the current [dotnet core SDK](https://dotnet.microsoft.com/download/dotnet-core/2.2). 27 | 28 | 29 | #### AppVeyor 30 | 31 | At this time AppVeyor does not support the RTM of Visual Studio 2019. However the [Visual Studio 2019 preview image](https://www.appveyor.com/docs/build-environment/#visual-studio-preview-images) can be used via `image: Visual Studio 2019 Preview` in `appveyor.yml`. 32 | 33 | 34 | #### TravisCI 35 | 36 | MSBuild16 can be used on TravisCI using the [xenial distro](https://docs.travis-ci.com/user/reference/xenial/) and [dotnet 2.2.202](https://docs.travis-ci.com/user/languages/csharp/#net-core). An example `.travis.yml` config: 37 | 38 | ``` 39 | language: csharp 40 | dist: xenial 41 | sudo: required 42 | mono: none 43 | dotnet: 2.2.202 44 | script: 45 | - dotnet build /p:Configuration=Release /p:Platform="Any CPU" --framework netcoreapp2.2 46 | - dotnet test --no-build --configuration Release --framework netcoreapp2.2 47 | ``` 48 | 49 | 50 | ### mdb symbols no longer supported 51 | 52 | Move over to pdb symbols or embedded symbols. 53 | 54 | 55 | ### Update NuGet 56 | 57 | Update to Version 5 of the [Fody NuGet package](https://www.nuget.org/packages/Fody/). 58 | 59 | 60 | ## Weavers 61 | 62 | The following steps are only required for people creating Fody Weavers. 63 | 64 | This also applies to [in solution weaving](in-solution-weaving.md). 65 | 66 | **Weavers targeting Version 4 of Fody are compatible with Version 5.** 67 | 68 | 69 | ### Update to MSBuild16 70 | 71 | As outlined above in the Consumers section 72 | 73 | 74 | ### Update the weaver project to be only netstandard2.0 75 | 76 | Weavers projects (`Name.Fody.csproj`) now only need to target netstandard2.0. So change `net46;netstandard2.0` to `netstandard2.0`. 77 | 78 | 79 | ### Update test project to a compatible framework 80 | 81 | Fody now requires net472 at build time, so the test project (usually `Name.Fody.Test.csproj` or `Test.csproj`) needs to be changed to compatible frameworks. Usually this means changing `net46;netcoreapp2.2` to `net472;netcoreapp2.2`. 82 | 83 | 84 | ### Ensure correct build order 85 | 86 | MSBuild16 now properly supports project build order dependencies. See [Addin Development - Build Order](addin-development.md#build-order). 87 | 88 | 89 | ### Update NuGet packages 90 | 91 | Update to Version 5 of the `Fody`, `FodyHelpers`, and `FodyPackaging` NuGet packages. -------------------------------------------------------------------------------- /pages/supported-runtimes-and-ide.md: -------------------------------------------------------------------------------- 1 | 7 | 8 | # Supported .net runtimes and IDE 9 | 10 | 11 | ## Visual Studio support 12 | 13 | Fody requires one of the following at build time: 14 | 15 | * [MSBuild 16](https://docs.microsoft.com/en-us/visualstudio/msbuild/msbuild?view=vs-2019) which ships with Visual Studio 2019. 16 | * [dotnet core SDK 2.2.105](https://dotnet.microsoft.com/download) (or higher) to work with [dotnet build](https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-build). 17 | 18 | 19 | ## Project formats 20 | 21 | The following are not supported 22 | 23 | * Projects using the [project.json](https://docs.microsoft.com/en-us/nuget/schema/project-json). 24 | * Projects using the xproj. 25 | 26 | To tell the difference between the old and new csproj formats. 27 | 28 | The old format starts with: 29 | 30 | ``` 31 | 32 | ``` 33 | 34 | The new format starts with: 35 | 36 | ``` 37 | 38 | ``` 39 | 40 | For all these scenarios is it instead recommended to move to the new SDK style projects. 41 | 42 | References 43 | 44 | * [Bye-Bye Project.json and .xproj and welcome back .csproj](http://www.talkingdotnet.com/bye-bye-project-json-xproj-welcome-back-csproj/) 45 | * [Project.json to MSBuild conversion guide](http://www.natemcmaster.com/blog/2017/01/19/project-json-to-csproj/) 46 | * [Migrate from project.json to new SDK style projects](https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-migrate) 47 | 48 | 49 | ## Target framework 50 | 51 | * Classic .NET: See *Support ended* in [NET Framework version history](https://en.wikipedia.org/wiki/.NET_Framework_version_history#Overview). i.e only 4.5.2 and above is supported. 52 | * .NET core: Follows [.NET Core Support Policy](https://www.microsoft.com/net/core/support). 53 | 54 | No explicit code is in place to check for non supported versions, and throw an error. As such earlier versions of .net may work as a side effect. It's all up to the individual weavers used and what version they are able to support. 55 | 56 | Any bugs found must be reproduced in a supported version. 57 | 58 | Downstream weavers are recommended to follow the above guidelines. 59 | 60 | 61 | ### Reasons 62 | 63 | While it may seam trivial to "implement support for earlier versions of .net" the long term support implications are too costly. For example to support earlier versions of .net require 64 | 65 | * Custom VMs to verify problems. 66 | * Added complexity to setting up build environment. 67 | * Bugs in unsupported versions in .NET may be manifest as bugs in Fody. 68 | 69 | 70 | ## Implications if using using Fody on project 71 | 72 | Fody provides the build integration for the weavers. The runtime that the project may target only depends on the weaver(s) being used; see the documentation of the individual weavers to know what frameworks are supported. 73 | 74 | The target framework(s) supported by a weaver is up to the designer of the individual weaver. Since extending the range of supported frameworks might introduce extra overhead, not all possible framework versions might be actively supported. 75 | -------------------------------------------------------------------------------- /pages/upgradeGuideV5.md: -------------------------------------------------------------------------------- 1 | 7 | 8 | # Version 5 upgrade guide 9 | 10 | 11 | ## Consumers 12 | 13 | Fody now requires MSBuild16. 14 | 15 | This means any tool chain being used needs to support MSBuild16. For example: 16 | 17 | * Visual Studio 19. 18 | * [dotnet core SDK 2.2](https://dotnet.microsoft.com/download/dotnet-core/2.2). 19 | * JetBrains Rider 2018.3.4. 20 | 21 | To ensure all consumers are using the correct build tooling, ensure the `.sln` file starts with: 22 | 23 | ``` 24 | Microsoft Visual Studio Solution File, Format Version 12.00 25 | # Visual Studio Version 16 26 | VisualStudioVersion = 16.0.28721.148 27 | MinimumVisualStudioVersion = 16.0.28721.148 28 | ``` 29 | 30 | 31 | ### Build server 32 | 33 | To use MSBuild install [Build Tools for Visual Studio 2019](https://visualstudio.microsoft.com/downloads/#vstool-2019). To use dotnet build install the current [dotnet core SDK](https://dotnet.microsoft.com/download/dotnet-core/2.2). 34 | 35 | 36 | #### AppVeyor 37 | 38 | At this time AppVeyor does not support the RTM of Visual Studio 2019. However the [Visual Studio 2019 preview image](https://www.appveyor.com/docs/build-environment/#visual-studio-preview-images) can be used via `image: Visual Studio 2019 Preview` in `appveyor.yml`. 39 | 40 | 41 | #### TravisCI 42 | 43 | MSBuild16 can be used on TravisCI using the [xenial distro](https://docs.travis-ci.com/user/reference/xenial/) and [dotnet 2.2.202](https://docs.travis-ci.com/user/languages/csharp/#net-core). An example `.travis.yml` config: 44 | 45 | ``` 46 | language: csharp 47 | dist: xenial 48 | sudo: required 49 | mono: none 50 | dotnet: 2.2.202 51 | script: 52 | - dotnet build /p:Configuration=Release /p:Platform="Any CPU" --framework netcoreapp2.2 53 | - dotnet test --no-build --configuration Release --framework netcoreapp2.2 54 | ``` 55 | 56 | 57 | ### mdb symbols no longer supported 58 | 59 | Move over to pdb symbols or embedded symbols. 60 | 61 | 62 | ### Update NuGet 63 | 64 | Update to Version 5 of the [Fody NuGet package](https://www.nuget.org/packages/Fody/). 65 | 66 | 67 | ## Weavers 68 | 69 | The following steps are only required for people creating Fody Weavers. 70 | 71 | This also applies to [in solution weaving](in-solution-weaving.md). 72 | 73 | **Weavers targeting Version 4 of Fody are compatible with Version 5.** 74 | 75 | 76 | ### Update to MSBuild16 77 | 78 | As outlined above in the Consumers section 79 | 80 | 81 | ### Update the weaver project to be only netstandard2.0 82 | 83 | Weavers projects (`Name.Fody.csproj`) now only need to target netstandard2.0. So change `net46;netstandard2.0` to `netstandard2.0`. 84 | 85 | 86 | ### Update test project to a compatible framework 87 | 88 | Fody now requires net472 at build time, so the test project (usually `Name.Fody.Test.csproj` or `Test.csproj`) needs to be changed to compatible frameworks. Usually this means changing `net46;netcoreapp2.2` to `net472;netcoreapp2.2`. 89 | 90 | 91 | ### Ensure correct build order 92 | 93 | MSBuild16 now properly supports project build order dependencies. See [Addin Development - Build Order](addin-development.md#build-order). 94 | 95 | 96 | ### Update NuGet packages 97 | 98 | Update to Version 5 of the `Fody`, `FodyHelpers`, and `FodyPackaging` NuGet packages. 99 | -------------------------------------------------------------------------------- /BasicFodyAddin/BasicFodyAddin.sln: -------------------------------------------------------------------------------- 1 | Microsoft Visual Studio Solution File, Format Version 12.00 2 | # Visual Studio Version 16 3 | VisualStudioVersion = 16.0.29201.188 4 | MinimumVisualStudioVersion = 16.0.29201.188 5 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BasicFodyAddin.Fody", "BasicFodyAddin.Fody\BasicFodyAddin.Fody.csproj", "{C3578A7B-09A6-4444-9383-0DEAFA4958BD}" 6 | EndProject 7 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tests", "Tests\Tests.csproj", "{5A86453B-96FB-4B6E-A283-225BB9F753D3}" 8 | EndProject 9 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AssemblyToProcess", "AssemblyToProcess\AssemblyToProcess.csproj", "{E97E649F-B703-47E3-B18A-0871D3498742}" 10 | EndProject 11 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BasicFodyAddin", "BasicFodyAddin\BasicFodyAddin.csproj", "{9BCD4937-CB40-4AE1-B884-16F37D64B3C7}" 12 | ProjectSection(ProjectDependencies) = postProject 13 | {C3578A7B-09A6-4444-9383-0DEAFA4958BD} = {C3578A7B-09A6-4444-9383-0DEAFA4958BD} 14 | EndProjectSection 15 | EndProject 16 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{C65B13FA-E7BB-421E-848A-CD02D730643E}" 17 | ProjectSection(SolutionItems) = preProject 18 | Directory.Build.props = Directory.Build.props 19 | EndProjectSection 20 | EndProject 21 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SmokeTest", "SmokeTest\SmokeTest.csproj", "{3B4ED4A9-C8F0-4B75-A5C7-B22213B7A3DC}" 22 | EndProject 23 | Global 24 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 25 | Debug|Any CPU = Debug|Any CPU 26 | Release|Any CPU = Release|Any CPU 27 | EndGlobalSection 28 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 29 | {C3578A7B-09A6-4444-9383-0DEAFA4958BD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 30 | {C3578A7B-09A6-4444-9383-0DEAFA4958BD}.Debug|Any CPU.Build.0 = Debug|Any CPU 31 | {C3578A7B-09A6-4444-9383-0DEAFA4958BD}.Release|Any CPU.ActiveCfg = Release|Any CPU 32 | {C3578A7B-09A6-4444-9383-0DEAFA4958BD}.Release|Any CPU.Build.0 = Release|Any CPU 33 | {5A86453B-96FB-4B6E-A283-225BB9F753D3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 34 | {5A86453B-96FB-4B6E-A283-225BB9F753D3}.Debug|Any CPU.Build.0 = Debug|Any CPU 35 | {5A86453B-96FB-4B6E-A283-225BB9F753D3}.Release|Any CPU.ActiveCfg = Release|Any CPU 36 | {5A86453B-96FB-4B6E-A283-225BB9F753D3}.Release|Any CPU.Build.0 = Release|Any CPU 37 | {E97E649F-B703-47E3-B18A-0871D3498742}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 38 | {E97E649F-B703-47E3-B18A-0871D3498742}.Debug|Any CPU.Build.0 = Debug|Any CPU 39 | {E97E649F-B703-47E3-B18A-0871D3498742}.Release|Any CPU.ActiveCfg = Release|Any CPU 40 | {E97E649F-B703-47E3-B18A-0871D3498742}.Release|Any CPU.Build.0 = Release|Any CPU 41 | {9BCD4937-CB40-4AE1-B884-16F37D64B3C7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 42 | {9BCD4937-CB40-4AE1-B884-16F37D64B3C7}.Debug|Any CPU.Build.0 = Debug|Any CPU 43 | {9BCD4937-CB40-4AE1-B884-16F37D64B3C7}.Release|Any CPU.ActiveCfg = Release|Any CPU 44 | {9BCD4937-CB40-4AE1-B884-16F37D64B3C7}.Release|Any CPU.Build.0 = Release|Any CPU 45 | {3B4ED4A9-C8F0-4B75-A5C7-B22213B7A3DC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 46 | {3B4ED4A9-C8F0-4B75-A5C7-B22213B7A3DC}.Debug|Any CPU.Build.0 = Debug|Any CPU 47 | {3B4ED4A9-C8F0-4B75-A5C7-B22213B7A3DC}.Release|Any CPU.ActiveCfg = Release|Any CPU 48 | {3B4ED4A9-C8F0-4B75-A5C7-B22213B7A3DC}.Release|Any CPU.Build.0 = Release|Any CPU 49 | EndGlobalSection 50 | GlobalSection(SolutionProperties) = preSolution 51 | HideSolutionNode = FALSE 52 | EndGlobalSection 53 | GlobalSection(ExtensibilityGlobals) = postSolution 54 | SolutionGuid = {72468F54-ED83-4BA1-9564-26475540EF44} 55 | EndGlobalSection 56 | EndGlobal 57 | -------------------------------------------------------------------------------- /BasicFodyAddin/BasicFodyAddin.Fody/ModuleWeaver.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using Mono.Cecil; 4 | using Mono.Cecil.Rocks; 5 | using Mono.Cecil.Cil; 6 | using Fody; 7 | 8 | #region ModuleWeaver 9 | 10 | public class ModuleWeaver : 11 | BaseModuleWeaver 12 | { 13 | #region Execute 14 | 15 | public override void Execute() 16 | { 17 | var ns = GetNamespace(); 18 | var type = new TypeDefinition(ns, "Hello", TypeAttributes.Public, TypeSystem.ObjectReference); 19 | 20 | AddConstructor(type); 21 | 22 | AddHelloWorld(type); 23 | 24 | ModuleDefinition.Types.Add(type); 25 | WriteInfo("Added type 'Hello' with method 'World'."); 26 | } 27 | 28 | #endregion 29 | 30 | #region GetAssembliesForScanning 31 | 32 | public override IEnumerable GetAssembliesForScanning() 33 | { 34 | yield return "netstandard"; 35 | yield return "mscorlib"; 36 | } 37 | 38 | #endregion 39 | 40 | string GetNamespace() 41 | { 42 | var namespaceFromConfig = GetNamespaceFromConfig(); 43 | var namespaceFromAttribute = GetNamespaceFromAttribute(); 44 | if (namespaceFromConfig != null && namespaceFromAttribute != null) 45 | { 46 | throw new WeavingException("Configuring namespace from both Config and Attribute is not supported."); 47 | } 48 | 49 | if (namespaceFromAttribute != null) 50 | { 51 | return namespaceFromAttribute; 52 | } 53 | 54 | return namespaceFromConfig; 55 | } 56 | 57 | string GetNamespaceFromConfig() 58 | { 59 | var attribute = Config?.Attribute("Namespace"); 60 | if (attribute == null) 61 | { 62 | return null; 63 | } 64 | 65 | var value = attribute.Value; 66 | ValidateNamespace(value); 67 | return value; 68 | } 69 | 70 | string GetNamespaceFromAttribute() 71 | { 72 | var attributes = ModuleDefinition.Assembly.CustomAttributes; 73 | var namespaceAttribute = attributes 74 | .SingleOrDefault(x => x.AttributeType.FullName == "NamespaceAttribute"); 75 | if (namespaceAttribute == null) 76 | { 77 | return null; 78 | } 79 | 80 | attributes.Remove(namespaceAttribute); 81 | var value = (string)namespaceAttribute.ConstructorArguments.First().Value; 82 | ValidateNamespace(value); 83 | return value; 84 | } 85 | 86 | static void ValidateNamespace(string value) 87 | { 88 | if (value is null || string.IsNullOrWhiteSpace(value)) 89 | { 90 | throw new WeavingException("Invalid namespace"); 91 | } 92 | } 93 | 94 | void AddConstructor(TypeDefinition newType) 95 | { 96 | var attributes = MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName; 97 | var method = new MethodDefinition(".ctor", attributes, TypeSystem.VoidReference); 98 | var objectConstructor = ModuleDefinition.ImportReference(TypeSystem.ObjectDefinition.GetConstructors().First()); 99 | var processor = method.Body.GetILProcessor(); 100 | processor.Emit(OpCodes.Ldarg_0); 101 | processor.Emit(OpCodes.Call, objectConstructor); 102 | processor.Emit(OpCodes.Ret); 103 | newType.Methods.Add(method); 104 | } 105 | 106 | void AddHelloWorld(TypeDefinition newType) 107 | { 108 | var method = new MethodDefinition("World", MethodAttributes.Public, TypeSystem.StringReference); 109 | var processor = method.Body.GetILProcessor(); 110 | processor.Emit(OpCodes.Ldstr, "Hello World"); 111 | processor.Emit(OpCodes.Ret); 112 | newType.Methods.Add(method); 113 | } 114 | 115 | #region ShouldCleanReference 116 | public override bool ShouldCleanReference => true; 117 | #endregion 118 | } 119 | 120 | #endregion -------------------------------------------------------------------------------- /pages/addin-packaging.md: -------------------------------------------------------------------------------- 1 | 7 | 8 | # Addin packaging 9 | 10 | 11 | ## Convention 12 | 13 | The convention for Fody addin NuGet packages is as follows: 14 | 15 | 📁 build
16 |     AddinName.Fody.props
17 | 📁 lib
18 |    📁 net452
19 |        AddinName.dll
20 |        AddinName.xml
21 |    📁 netstandard2.0
22 |        AddinName.dll
23 |        AddinName.xml
24 | 📁 weaver
25 |     AddinName.Fody.dll
26 |     AddinName.Fody.xcf
27 | 28 | 29 | ### Convention Descriptions 30 | 31 | 32 | * `build/AddinName.Fody.props`: Facilitates [addin discovery](addin-discovery.md) via an [props file included by NuGet](https://docs.microsoft.com/en-us/nuget/create-packages/creating-a-package#including-msbuild-props-and-targets-in-a-package). 33 | * `lib`: Contains the [Lib/Reference project](addin-development.md#Lib/Reference-project) for all [supported target frameworks](https://docs.microsoft.com/en-us/nuget/create-packages/supporting-multiple-target-frameworks). 34 | * `weaver`: Contains the [Weaver Project](addin-development.md#Weaver-Project) assembly. Also contains the XCF file to [Supporting intellisense for FodyWeavers.xml](addin-development.md#Supporting-intellisense-for-FodyWeavers.xml). 35 | 36 | 37 | ## FodyPackaging NuGet Package 38 | 39 | The [FodyPackaging NuGet Package](https://www.nuget.org/packages/FodyPackaging/) simplifies following the above convention. 40 | 41 | 42 | ### MSBuild props and targets 43 | 44 | The below files are include as [MSBuild props and targets in a package](https://docs.microsoft.com/en-us/nuget/create-packages/creating-a-package#including-msbuild-props-and-targets-in-a-package). 45 | 46 | 47 | #### FodyPackaging.props 48 | 49 | 50 | 51 | ```props 52 | 53 | 54 | $(MSBuildProjectName).Fody 55 | ILWeaving, Fody, Cecil, AOP 56 | true 57 | $(TargetsForTfmSpecificContentInPackage);IncludeFodyFiles 58 | true 59 | true 60 | $(NoWarn);NU5118 61 | true 62 | ..\$(PackageId)\bin\$(Configuration)\ 63 | $(MSBuildThisFileDirectory)..\Weaver.props 64 | 65 | 66 | 67 | ``` 68 | anchor 69 | 70 | 71 | 72 | #### FodyPackaging.targets 73 | 74 | 75 | 76 | ```targets 77 | 78 | 79 | 80 | $(WeaverDirPath)\netstandard2.0\$(PackageId).dll 81 | $(WeaverDirPath)\netstandard2.0\$(PackageId).xcf 82 | 83 | 84 | 86 | 87 | 88 | 91 | 93 | 95 | 96 | 97 | 98 | 99 | ``` 100 | anchor 101 | 102 | 103 | 104 | ### Weaver.props 105 | 106 | Included in the consuming package to facilitate [addin discovery](addin-discovery.md). 107 | 108 | 109 | 110 | ```props 111 | 112 | 113 | 114 | 115 | 116 | 117 | ``` 118 | anchor 119 | 120 | -------------------------------------------------------------------------------- /pages/mdsource/licensing-patron-faq.source.md: -------------------------------------------------------------------------------- 1 | # Licensing/Patron FAQ 2 | 3 | Fody requires significant effort to maintain. As such it relies on financial contributions to ensure its long term viability. 4 | 5 | **It is expected that all developers using Fody [become a Patron on OpenCollective](https://opencollective.com/fody/contribute/patron-3059).** 6 | 7 | 8 | ## Honesty System / Enforcement 9 | 10 | It is an honesty system with no code or legal enforcement. When raising an issue or a pull request, the GitHub Id may be checked to ensure they are a patron, and that issue/PR may be closed without further examination. This process will depend on the issue quality, and the impact on the larger user base. If a individual or organization has no interest in the long term sustainability of the project, then they are legally free to ignore the honesty system. 11 | 12 | 13 | ## Why charge for open source? 14 | 15 | * [Open-Source Maintainers are Jerks | Nick Randolph & Geoffrey Huntley](https://vimeo.com/296579853) 16 | * [FOSS is free as in toilet | Geoffroy Couprie](http://unhandledexpression.com/general/2018/11/27/foss-is-free-as-in-toilet.html) 17 | * [How to Charge for Open Source | Mike Perham](https://www.mikeperham.com/2015/11/23/how-to-charge-for-your-open-source/) 18 | * [Sustain OSS: The Report](https://sustainoss.org/assets/pdf/SustainOSS-west-2017-report.pdf) 19 | * [Open Source Maintainers Owe Nothing | Mike McQuaid](https://mikemcquaid.com/2018/03/19/open-source-maintainers-owe-you-nothing/) 20 | * [Who should fund open source projects? | Jane Elizabeth](https://jaxenter.com/who-funds-open-source-projects-133222.html) 21 | * [Apply at OSS Inc today| Ryan Chenkie](https://twitter.com/ryanchenkie/status/1067801413974032385) 22 | * [The Ethics of Unpaid Labor and the OSS Community | Ashe Dryden](https://www.ashedryden.com/blog/the-ethics-of-unpaid-labor-and-the-oss-community) 23 | 24 | 25 | ## So what OSS license are projects using? 26 | 27 | Fody (all code, NuGets and binaries) are under the [MIT License](https://opensource.org/licenses/MIT). 28 | 29 | 30 | ## Why not use a modified MIT license? 31 | 32 | Using any OSS license in a modified form causes significant problems with adoption of tools. There is no simplified guidance on using modified licenses. For example they are not included in [choose a license](https://choosealicense.com/) or [tldr legal](https://tldrlegal.com/). It often forces an organization to obtain approval from a legal department. It means any consuming tools need to ensure that the modified license does not propagate in an undesirable way. 33 | 34 | 35 | ## But shouldn't OSS be completely free and supported by the community through their contributions? 36 | 37 | Yes in theory this is true, however the long term reality has shown this not to be the case. The vast majority of consumers of open source projects do not contribute enough to ensure those project survive. This results in a small core team spending large amounts of their own free time maintaining projects. 38 | 39 | 40 | ## Is support now included as part of the cost? 41 | 42 | No. As per the [MIT License](https://opensource.org/licenses/MIT): 43 | 44 | > the software is provided "as is", without warranty of any kind 45 | 46 | For a supported product, instead consider [PostSharp](https://www.postsharp.net/?utm_source=fody&utm_medium=referral). PostSharp is a mature and supported product that is used by Fortune 500 companies as well as startups, and it doesn't require knowledge of IL. 47 | 48 | They offer a free edition and their feature list includes: Aspect-Oriented Programming, Logging, INotifyPropertyChanged, Caching, Transactions, Security, Multithreading, Code Contracts, XAML plumbing, and Architecture Validation. 49 | 50 | 51 | ## But it is MIT, can't I use it for free? 52 | 53 | All projects are under [MIT](https://opensource.org/licenses/MIT) so the community backing honesty system can be ignored. So legally it is free, morally it is paid. 54 | 55 | 56 | ## Do I need to be a Patron to contribute a Pull Request? 57 | 58 | Yes. Users must be a Patron to be a user of Fody. Contributing Pull Requests does not cancel this out. It may seem unfair to expect people both contribute PRs and also financially back this project. However it is important to remember the effort in reviewing and merging a PR is often similar to that of creating the PR. Also the project maintainers are committing to support that added code (feature or bug fix) for the life of the project. Pull Requests from non-Patrons, that are of significant value to the larger Fody user base, may justify the effort in reviewing and merging. 59 | 60 | 61 | ## Do I need to be a Patron to raise an issue? 62 | 63 | Yes. Users must be a Patron to be a user of Fody. As such when raising an issue (question, bug or feature request) and not a Patron, the issue may not be actively triaged, and eventually closed as stale. Issues from non-Patrons, that are bugs and are highly likely to effect the larger Fody user base, may justify the effort and be handled. 64 | 65 | 66 | ## Organization licensing 67 | 68 | 69 | ### How to handle multiple developers 70 | 71 | There are two options for an organization. 72 | 73 | 1. Apply a multiplier to the Patron cost. 74 | The [Patron tier](https://opencollective.com/fody/order/3059) has no upper bound on the monthly amount. This allows an organization with multiple developers to pay a single monthly price. For example: An organization with 5 developers would pay $15 per month, i.e. 5 x $3 per patron. An organization with 10 developers would pay $30 per month, i.e. 10 x $3 per patron and so on. 75 | 2. Create an Open Collective organization 76 | A organization can [Create an Open Collective organization](https://opencollective.com/become-a-sponsor) and then allow their developers to draw on the funds from that organization. See [FAQ for backers](https://opencollective.com/faq/backers). This is the recommended option as it also opens up the opportunity for developers to select other projects to support. 77 | 78 | 79 | ### Do all developers in a organization need to become Patrons? 80 | 81 | No. Only those coding against projects that directly, or indirectly, consume the [Fody NuGet package](https://www.nuget.org/packages/Fody/). 82 | 83 | 84 | ### Can only one developer of an organization become a patron? 85 | 86 | Yes, since the only point of (optional) enforcement is when an issue or PR is raised, then legally an organization can ignore the honesty system and route all issues and PRs though a single GitHub user account. However if a single GitHub user account is drawing on significant time to support, they may be requested to purchase some [hourly support](https://opencollective.com/fody/order/7087). 87 | 88 | 89 | ## What about open source projects consume or producing Fody weavers? 90 | 91 | It is be expected that the core team of maintainers of any open source projects that consume or produce Fody weavers would become Patrons. Non core contributors do not need to become Patrons. For example, in the context of GitHub, this would be any people with push access to the the repository. The reasoning is that if a project is utilizing Fody, that should not be a blocker for the larger community from contributing to the project. 92 | 93 | 94 | ## Can I fork, re-use code, or start competing (possibly commercial) projects? 95 | 96 | Yes. 97 | 98 | 99 | ## What happens if I produce a library using Fody? 100 | 101 | Consumers of that produced library do not need to become Patrons. 102 | -------------------------------------------------------------------------------- /pages/mdsource/configuration.source.md: -------------------------------------------------------------------------------- 1 | # Configuration 2 | 3 | ## Configuring the weavers 4 | 5 | Fody requires an XML configuration that lists all weavers to be applied to the project. 6 | 7 | * It specifies the list of weavers that should be applied to the project. 8 | * Weavers are applied in the order listed in the configuration. 9 | * Weavers can also be configured here. See the documentation of each individual weaver to see what configuration options it has. 10 | 11 | The format is: 12 | 13 | ```xml 14 | 15 | 16 | 17 | 18 | ``` 19 | 20 | The `` element is mandatory and supports the following attributes: 21 | 22 | * `VerifyAssembly`: Set to `true` to run PEVerify on the build result. See [Assembly verification](#assembly-verification). 23 | * `VerifyIgnoreCodes`: A comma-separated list of error codes which should be ignored during assembly verification. See [Assembly verification](#assembly-verification). 24 | * `GenerateXsd`: Set to `false` to disable generation of the `FodyWeavers.xsd` file which provides [IntelliSense](https://docs.microsoft.com/en-us/visualstudio/ide/using-intellisense) support for `FodyWeavers.xml`. This overrides the `FodyGenerateXsd` MSBuild property. 25 | 26 | The content of the `` element is a list of all weavers, where the name of the element corresponds to the weaver name. 27 | 28 | 29 | ### Configuration options 30 | 31 | There are several ways to specify the configuration 32 | 33 | 34 | #### A file in each project directory 35 | 36 | The default is a file named `FodyWeavers.xml` in each projects directory. 37 | 38 | * If it is missing, and no other configuration can be found, a default file will be created the first time the project is built. 39 | * An XML schema will be created aside of this file, to provide [IntelliSense](https://docs.microsoft.com/en-us/visualstudio/ide/using-intellisense) support for editing the `FodyWeavers.xml` 40 | * This file must not contain entries for weavers that are not installed. However, entries can be ommited if they are defined in one of the alternate configurations. 41 | 42 | 43 | #### An MSBuild property in the project file 44 | 45 | An alternate way is to add a property named `WeaverConfiguration` in the project file: 46 | 47 | ```xml 48 | 49 | 50 | ... 51 | Some Value 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | ``` 60 | 61 | The content of this property is the same as described above 62 | 63 | * This has highest precedence, it overrides any entries of the other configurations 64 | * Use MSBuild logic to dynamically control the behavior 65 | * Add the configuration e.g. once in the `Directory.build.props` file to share the same configuration among several projects. 66 | * To support sharing the configuration among several projects, entries for weavers that are not installed for a particular project are ignored, configure the superset of all weavers installed in all projects. 67 | * [IntelliSense](https://docs.microsoft.com/en-us/visualstudio/ide/using-intellisense) for the configuration is not available here 68 | 69 | 70 | #### A file in the solution directory 71 | 72 | The configuration may be shared among all projects of the solution by adding one file named `FodyWeavers.xml` in the solution directory. 73 | 74 | * [IntelliSense](https://docs.microsoft.com/en-us/visualstudio/ide/using-intellisense) for the configuration is not available here 75 | * Entries for weavers that are not installed for a particular project are ignored, so the superset can be configured for of all weavers installed in all projects. 76 | * This option has the lowest precedence and will be overwritten by the other options 77 | 78 | 79 | ### Merging configurations 80 | 81 | When multiple configurations are provided, the one with the lowest precedence will control the execution order of the weaver, while the one with the higher precedence will override the content of the configuration node. 82 | 83 | Consider this combination: 84 | 85 | `FodyWeavers.xml` in the solution directory: 86 | 87 | ```xml 88 | 89 | 90 | 91 | 92 | ``` 93 | 94 | --- 95 | 96 | `FodyWeavers.xml` in the project directory: 97 | 98 | ```xml 99 | 100 | 101 | 102 | 103 | 104 | ``` 105 | 106 | --- 107 | 108 | `WeaverConfiguration` entry in the project: 109 | 110 | ```xml 111 | 112 | 113 | 114 | 115 | 116 | 117 | ``` 118 | 119 | --- 120 | 121 | This will result in an effective configuration of 122 | 123 | ```xml 124 | 125 | 126 | 127 | 128 | 129 | ``` 130 | 131 | for non-debug and 132 | 133 | ```xml 134 | 135 | 136 | 137 | 138 | 139 | ``` 140 | for debug builds. 141 | 142 | To verify which configuration is active the configuration source can be found in the log when the output verbosity is set to detailed. 143 | 144 | 145 | ## Controlling the behavior of Fody 146 | 147 | The following options can be set through MSBuild properties: 148 | 149 | * `DisableFody`: Set to `true` to disable Fody entirely. 150 | * `FodyGenerateXsd`: Set to `false` to disable generation of the `FodyWeavers.xsd` file which provides [IntelliSense](https://docs.microsoft.com/en-us/visualstudio/ide/using-intellisense) support for `FodyWeavers.xml`. 151 | * `FodyTreatWarningsAsErrors`: Controls whether warnings generated by Fody should be considered as errors. Defaults to the value of `$(TreatWarningsAsErrors)`, which is `false` by default. 152 | * `FodyVerifyAssembly`: Enables [assembly verification](#assembly-verification) with PEVerify. 153 | 154 | 155 | ## Defining dependencies in the build order 156 | 157 | This can be done by defining a property group project named `FodyDependsOnTargets`. The content of this property will then be passed to the `DependsOnTargets` of the Fody weaving task. 158 | 159 | > DependsOnTargets: The targets that must be executed before this target can be executed or top-level dependency analysis can occur. Multiple targets are separated by semicolons. 160 | 161 | An example use case of this is to force Fody to run after [CodeContracts](https://docs.microsoft.com/en-us/dotnet/framework/debug-trace-profile/code-contracts). 162 | 163 | ```xml 164 | 165 | 166 | CodeContractRewrite 167 | 168 | 169 | ``` 170 | 171 | 172 | ## Assembly verification 173 | 174 | Post build verification via [PeVerify](https://docs.microsoft.com/en-us/dotnet/framework/tools/peverify-exe-peverify-tool) is supported. 175 | 176 | To enable do one of the following 177 | 178 | Add `VerifyAssembly="true"` to FodyWeavers.xml: 179 | 180 | ```xml 181 | 182 | 183 | 184 | ``` 185 | 186 | Add a build constant with the value of `FodyVerifyAssembly` 187 | 188 | To send ignore codes to PeVerify use `VerifyIgnoreCodes`. 189 | 190 | ```xml 191 | 193 | 194 | 195 | ``` 196 | -------------------------------------------------------------------------------- /pages/licensing-patron-faq.md: -------------------------------------------------------------------------------- 1 | 7 | 8 | # Licensing/Patron FAQ 9 | 10 | Fody requires significant effort to maintain. As such it relies on financial contributions to ensure its long term viability. 11 | 12 | **It is expected that all developers using Fody [become a Patron on OpenCollective](https://opencollective.com/fody/contribute/patron-3059).** 13 | 14 | 15 | ## Honesty System / Enforcement 16 | 17 | It is an honesty system with no code or legal enforcement. When raising an issue or a pull request, the GitHub Id may be checked to ensure they are a patron, and that issue/PR may be closed without further examination. This process will depend on the issue quality, and the impact on the larger user base. If a individual or organization has no interest in the long term sustainability of the project, then they are legally free to ignore the honesty system. 18 | 19 | 20 | ## Why charge for open source? 21 | 22 | * [Open-Source Maintainers are Jerks | Nick Randolph & Geoffrey Huntley](https://vimeo.com/296579853) 23 | * [FOSS is free as in toilet | Geoffroy Couprie](http://unhandledexpression.com/general/2018/11/27/foss-is-free-as-in-toilet.html) 24 | * [How to Charge for Open Source | Mike Perham](https://www.mikeperham.com/2015/11/23/how-to-charge-for-your-open-source/) 25 | * [Sustain OSS: The Report](https://sustainoss.org/assets/pdf/SustainOSS-west-2017-report.pdf) 26 | * [Open Source Maintainers Owe Nothing | Mike McQuaid](https://mikemcquaid.com/2018/03/19/open-source-maintainers-owe-you-nothing/) 27 | * [Who should fund open source projects? | Jane Elizabeth](https://jaxenter.com/who-funds-open-source-projects-133222.html) 28 | * [Apply at OSS Inc today| Ryan Chenkie](https://twitter.com/ryanchenkie/status/1067801413974032385) 29 | * [The Ethics of Unpaid Labor and the OSS Community | Ashe Dryden](https://www.ashedryden.com/blog/the-ethics-of-unpaid-labor-and-the-oss-community) 30 | 31 | 32 | ## So what OSS license are projects using? 33 | 34 | Fody (all code, NuGets and binaries) are under the [MIT License](https://opensource.org/licenses/MIT). 35 | 36 | 37 | ## Why not use a modified MIT license? 38 | 39 | Using any OSS license in a modified form causes significant problems with adoption of tools. There is no simplified guidance on using modified licenses. For example they are not included in [choose a license](https://choosealicense.com/) or [tldr legal](https://tldrlegal.com/). It often forces an organization to obtain approval from a legal department. It means any consuming tools need to ensure that the modified license does not propagate in an undesirable way. 40 | 41 | 42 | ## But shouldn't OSS be completely free and supported by the community through their contributions? 43 | 44 | Yes in theory this is true, however the long term reality has shown this not to be the case. The vast majority of consumers of open source projects do not contribute enough to ensure those project survive. This results in a small core team spending large amounts of their own free time maintaining projects. 45 | 46 | 47 | ## Is support now included as part of the cost? 48 | 49 | No. As per the [MIT License](https://opensource.org/licenses/MIT): 50 | 51 | > the software is provided "as is", without warranty of any kind 52 | 53 | For a supported product, instead consider [PostSharp](https://www.postsharp.net/?utm_source=fody&utm_medium=referral). PostSharp is a mature and supported product that is used by Fortune 500 companies as well as startups, and it doesn't require knowledge of IL. 54 | 55 | They offer a free edition and their feature list includes: Aspect-Oriented Programming, Logging, INotifyPropertyChanged, Caching, Transactions, Security, Multithreading, Code Contracts, XAML plumbing, and Architecture Validation. 56 | 57 | 58 | ## But it is MIT, can't I use it for free? 59 | 60 | All projects are under [MIT](https://opensource.org/licenses/MIT) so the community backing honesty system can be ignored. So legally it is free, morally it is paid. 61 | 62 | 63 | ## Do I need to be a Patron to contribute a Pull Request? 64 | 65 | Yes. Users must be a Patron to be a user of Fody. Contributing Pull Requests does not cancel this out. It may seem unfair to expect people both contribute PRs and also financially back this project. However it is important to remember the effort in reviewing and merging a PR is often similar to that of creating the PR. Also the project maintainers are committing to support that added code (feature or bug fix) for the life of the project. Pull Requests from non-Patrons, that are of significant value to the larger Fody user base, may justify the effort in reviewing and merging. 66 | 67 | 68 | ## Do I need to be a Patron to raise an issue? 69 | 70 | Yes. Users must be a Patron to be a user of Fody. As such when raising an issue (question, bug or feature request) and not a Patron, the issue may not be actively triaged, and eventually closed as stale. Issues from non-Patrons, that are bugs and are highly likely to effect the larger Fody user base, may justify the effort and be handled. 71 | 72 | 73 | ## Organization licensing 74 | 75 | 76 | ### How to handle multiple developers 77 | 78 | There are two options for an organization. 79 | 80 | 1. Apply a multiplier to the Patron cost. 81 | The [Patron tier](https://opencollective.com/fody/order/3059) has no upper bound on the monthly amount. This allows an organization with multiple developers to pay a single monthly price. For example: An organization with 5 developers would pay $15 per month, i.e. 5 x $3 per patron. An organization with 10 developers would pay $30 per month, i.e. 10 x $3 per patron and so on. 82 | 2. Create an Open Collective organization 83 | A organization can [Create an Open Collective organization](https://opencollective.com/become-a-sponsor) and then allow their developers to draw on the funds from that organization. See [FAQ for backers](https://opencollective.com/faq/backers). This is the recommended option as it also opens up the opportunity for developers to select other projects to support. 84 | 85 | 86 | ### Do all developers in a organization need to become Patrons? 87 | 88 | No. Only those coding against projects that directly, or indirectly, consume the [Fody NuGet package](https://www.nuget.org/packages/Fody/). 89 | 90 | 91 | ### Can only one developer of an organization become a patron? 92 | 93 | Yes, since the only point of (optional) enforcement is when an issue or PR is raised, then legally an organization can ignore the honesty system and route all issues and PRs though a single GitHub user account. However if a single GitHub user account is drawing on significant time to support, they may be requested to purchase some [hourly support](https://opencollective.com/fody/order/7087). 94 | 95 | 96 | ## What about open source projects consume or producing Fody weavers? 97 | 98 | It is be expected that the core team of maintainers of any open source projects that consume or produce Fody weavers would become Patrons. Non core contributors do not need to become Patrons. For example, in the context of GitHub, this would be any people with push access to the the repository. The reasoning is that if a project is utilizing Fody, that should not be a blocker for the larger community from contributing to the project. 99 | 100 | 101 | ## Can I fork, re-use code, or start competing (possibly commercial) projects? 102 | 103 | Yes. 104 | 105 | 106 | ## What happens if I produce a library using Fody? 107 | 108 | Consumers of that produced library do not need to become Patrons. 109 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Fody 2 | 3 | The Home repository is the starting point for people to learn about Fody, the project. 4 | 5 | Fody is an extensible tool for weaving .net assemblies. It enables the manipulation of the IL of an assembly as part of a build, which requires a significant amount of plumbing code. This plumbing code involves knowledge of both the MSBuild and Visual Studio APIs. Fody attempts to eliminate that plumbing code through an extensible add-in model. This technique is very powerful, for example you can turn simple properties into full [INotifyPropertyChanged implementations](https://github.com/Fody/PropertyChanged), add [checks for null arguments](https://github.com/Fody/NullGuard), add [Method Timings](https://github.com/Fody/MethodTimer), even [make all your string comparisons case insensitive](https://github.com/Fody/Caseless). 6 | 7 | 8 | 9 | 10 | [Already a Patron? skip past this section](#endofbacking) 11 | 12 | 13 | ## Community backed 14 | 15 | Fody requires significant effort to maintain. As such it relies on financial support to ensure its long term viability. 16 | 17 | **It is expected that all developers using Fody [become a Patron on OpenCollective](https://opencollective.com/fody/contribute/patron-3059).** 18 | 19 | [See Licensing/Patron FAQ](https://github.com/Fody/Home/blob/master/pages/licensing-patron-faq.md) for more information. 20 | 21 | 22 | ### Gold Sponsors 23 | 24 | Support this project by [becoming a Gold Sponsor](https://opencollective.com/fody/contribute/gold-7088). A large company logo will be added here with a link to your website. 25 | 26 | PostSharp 27 | 28 | 29 | ### Silver Sponsors 30 | 31 | Support this project by [becoming a Silver Sponsor](https://opencollective.com/fody/contribute/silver-7086). A medium company logo will be added here with a link to your website. 32 | 33 | G-Research Particular Software 34 | 35 | 36 | ### Bronze Sponsors 37 | 38 | Support this project by [becoming a Bronze Sponsor](https://opencollective.com/fody/contribute/bronze-7085). The company avatar will show up here with a link to your OpenCollective Profile. 39 | 40 | 41 | 42 | 43 | ### Patrons and sponsors 44 | 45 | Thanks to all the backers and sponsors! Support this project by [becoming a patron](https://opencollective.com/fody/contribute/patron-3059). 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | ## Main Fody code repository 55 | 56 | The codebase of core Fody engine located at https://github.com/Fody/Fody. 57 | 58 | [![Chat on Gitter](https://img.shields.io/gitter/room/fody/fody.svg)](https://gitter.im/Fody/Fody) 59 | 60 | ## The plumbing tasks Fody handles 61 | 62 | * Injection of the MSBuild task into the build pipeline 63 | * Resolving the location of the assembly and pdb 64 | * Abstracts the complexities of logging to MSBuild 65 | * Reads the assembly and pdb into the Mono.Cecil object model 66 | * Re-applying the strong name if necessary 67 | * Saving the assembly and pdb 68 | 69 | Fody Uses [Mono.Cecil](http://www.mono-project.com/Cecil/) and an add-in based approach to modifying the IL of .net assemblies at compile time. 70 | 71 | * No install required to build. 72 | * Attributes are optional depending on the weavers used. 73 | * No runtime dependencies need to be deployed. 74 | 75 | 76 | ## Documentation and Further Learning 77 | 78 | * [Licensing and patron FAQ](https://github.com/Fody/Home/tree/master/pages/licensing-patron-faq.md)
79 | **It is expected that all developers using Fody [become a Patron on OpenCollective](https://opencollective.com/fody/order/3059).** See [Licensing/Patron FAQ](https://github.com/Fody/Home/tree/master/pages/licensing-patron-faq.md) for more information. 80 | * [Usage](https://github.com/Fody/Home/tree/master/pages/usage.md)
81 | Introduction to using Fody. 82 | * [Configuration](https://github.com/Fody/Home/tree/master/pages/configuration.md)
83 | All configuration options for Fody. 84 | * [Addin discovery](https://github.com/Fody/Home/tree/master/pages/addin-discovery.md)
85 | How addins are resolved. 86 | * [List of Fody weavers/addins](https://github.com/Fody/Home/tree/master/pages/addins.md)
87 | * [Changelog](https://github.com/Fody/Fody/milestones?state=closed) 88 | * [FodyAddinSamples](https://github.com/Fody/FodyAddinSamples)
89 | A GitHub repo that contains a working sample of every Fody addin. 90 | * [Common errors](https://github.com/Fody/Home/tree/master/pages/common-errors.md) 91 | * [In solution weaving](https://github.com/Fody/Home/tree/master/pages/in-solution-weaving.md)
92 | Writing an addin that manipulates IL within the same solution. 93 | * [ProcessedByFody class](https://github.com/Fody/Home/tree/master/pages/processedbyfody-class.md)
94 | Marker class added to target assemblies for diagnostic purposes. 95 | * [Strong naming](https://github.com/Fody/Home/tree/master/pages/strong-naming.md) 96 | * [Supported runtimes and IDE](https://github.com/Fody/Home/tree/master/pages/supported-runtimes-and-ide.md) 97 | * [Addin development](https://github.com/Fody/Home/tree/master/pages/addin-development.md)
98 | Building a new Fody addin. 99 | * [Addin packaging](https://github.com/Fody/Home/tree/master/pages/addin-packaging.md)
100 | Packaging and deployment of Fody weavers. 101 | * [BasicFodyAddin](/BasicFodyAddin)
102 | A simple project meant to illustrate how to build an addin. 103 | * [Fody Project Configuration Manager](https://github.com/tom-englert/ProjectConfigurationManager/wiki/6.-Fody)
104 | Provides an interactive tool that can support configuring weavers, which is especially helpful in solutions with many projects. 105 | * [Backers tracking/info](https://github.com/Fody/Home/tree/master/pages/backers.md) 106 | * [Donations](https://github.com/Fody/Home/tree/master/pages/donations.md)
107 | Every month the Fody project will donate a portion of funding raised to a charity or other cause. 108 | 109 | 110 | ## Naming 111 | 112 | The name "Fody" comes from the small birds that belong to the weaver family [Ploceidae](http://en.wikipedia.org/wiki/Fody). 113 | 114 | 115 | ## Credits 116 | 117 | Thanks to the following 118 | 119 | * [Jb Evain](https://github.com/jbevain) for the use of [Mono Cecil](https://github.com/jbevain/cecil) 120 | * [GitHub](https://github.com/) for project hosting 121 | * [JetBrains](https://www.jetbrains.com/resharper/) for the generous donation of [ReSharper](https://www.jetbrains.com/resharper/) licenses. 122 | * [xUnit](https://xunit.github.io/) 123 | * [AppVeyor](https://www.appveyor.com/) and [Travis CI](https://travis-ci.org/) for build and CI infrastructure 124 | * [NuGet](https://www.nuget.org/) for package delivery 125 | * [The Noun Project](https://thenounproject.com) for the Bird icon designed by Marco Hernandez 126 | -------------------------------------------------------------------------------- /pages/configuration.md: -------------------------------------------------------------------------------- 1 | 7 | 8 | # Configuration 9 | 10 | ## Configuring the weavers 11 | 12 | Fody requires an XML configuration that lists all weavers to be applied to the project. 13 | 14 | * It specifies the list of weavers that should be applied to the project. 15 | * Weavers are applied in the order listed in the configuration. 16 | * Weavers can also be configured here. See the documentation of each individual weaver to see what configuration options it has. 17 | 18 | The format is: 19 | 20 | ```xml 21 | 22 | 23 | 24 | 25 | ``` 26 | 27 | The `` element is mandatory and supports the following attributes: 28 | 29 | * `VerifyAssembly`: Set to `true` to run PEVerify on the build result. See [Assembly verification](#assembly-verification). 30 | * `VerifyIgnoreCodes`: A comma-separated list of error codes which should be ignored during assembly verification. See [Assembly verification](#assembly-verification). 31 | * `GenerateXsd`: Set to `false` to disable generation of the `FodyWeavers.xsd` file which provides [IntelliSense](https://docs.microsoft.com/en-us/visualstudio/ide/using-intellisense) support for `FodyWeavers.xml`. This overrides the `FodyGenerateXsd` MSBuild property. 32 | 33 | The content of the `` element is a list of all weavers, where the name of the element corresponds to the weaver name. 34 | 35 | 36 | ### Configuration options 37 | 38 | There are several ways to specify the configuration 39 | 40 | 41 | #### A file in each project directory 42 | 43 | The default is a file named `FodyWeavers.xml` in each projects directory. 44 | 45 | * If it is missing, and no other configuration can be found, a default file will be created the first time the project is built. 46 | * An XML schema will be created aside of this file, to provide [IntelliSense](https://docs.microsoft.com/en-us/visualstudio/ide/using-intellisense) support for editing the `FodyWeavers.xml` 47 | * This file must not contain entries for weavers that are not installed. However, entries can be ommited if they are defined in one of the alternate configurations. 48 | 49 | 50 | #### An MSBuild property in the project file 51 | 52 | An alternate way is to add a property named `WeaverConfiguration` in the project file: 53 | 54 | ```xml 55 | 56 | 57 | ... 58 | Some Value 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | ``` 67 | 68 | The content of this property is the same as described above 69 | 70 | * This has highest precedence, it overrides any entries of the other configurations 71 | * Use MSBuild logic to dynamically control the behavior 72 | * Add the configuration e.g. once in the `Directory.build.props` file to share the same configuration among several projects. 73 | * To support sharing the configuration among several projects, entries for weavers that are not installed for a particular project are ignored, configure the superset of all weavers installed in all projects. 74 | * [IntelliSense](https://docs.microsoft.com/en-us/visualstudio/ide/using-intellisense) for the configuration is not available here 75 | 76 | 77 | #### A file in the solution directory 78 | 79 | The configuration may be shared among all projects of the solution by adding one file named `FodyWeavers.xml` in the solution directory. 80 | 81 | * [IntelliSense](https://docs.microsoft.com/en-us/visualstudio/ide/using-intellisense) for the configuration is not available here 82 | * Entries for weavers that are not installed for a particular project are ignored, so the superset can be configured for of all weavers installed in all projects. 83 | * This option has the lowest precedence and will be overwritten by the other options 84 | 85 | 86 | ### Merging configurations 87 | 88 | When multiple configurations are provided, the one with the lowest precedence will control the execution order of the weaver, while the one with the higher precedence will override the content of the configuration node. 89 | 90 | Consider this combination: 91 | 92 | `FodyWeavers.xml` in the solution directory: 93 | 94 | ```xml 95 | 96 | 97 | 98 | 99 | ``` 100 | 101 | --- 102 | 103 | `FodyWeavers.xml` in the project directory: 104 | 105 | ```xml 106 | 107 | 108 | 109 | 110 | 111 | ``` 112 | 113 | --- 114 | 115 | `WeaverConfiguration` entry in the project: 116 | 117 | ```xml 118 | 119 | 120 | 121 | 122 | 123 | 124 | ``` 125 | 126 | --- 127 | 128 | This will result in an effective configuration of 129 | 130 | ```xml 131 | 132 | 133 | 134 | 135 | 136 | ``` 137 | 138 | for non-debug and 139 | 140 | ```xml 141 | 142 | 143 | 144 | 145 | 146 | ``` 147 | for debug builds. 148 | 149 | To verify which configuration is active the configuration source can be found in the log when the output verbosity is set to detailed. 150 | 151 | 152 | ## Controlling the behavior of Fody 153 | 154 | The following options can be set through MSBuild properties: 155 | 156 | * `DisableFody`: Set to `true` to disable Fody entirely. 157 | * `FodyGenerateXsd`: Set to `false` to disable generation of the `FodyWeavers.xsd` file which provides [IntelliSense](https://docs.microsoft.com/en-us/visualstudio/ide/using-intellisense) support for `FodyWeavers.xml`. 158 | * `FodyTreatWarningsAsErrors`: Controls whether warnings generated by Fody should be considered as errors. Defaults to the value of `$(TreatWarningsAsErrors)`, which is `false` by default. 159 | * `FodyVerifyAssembly`: Enables [assembly verification](#assembly-verification) with PEVerify. 160 | 161 | 162 | ## Defining dependencies in the build order 163 | 164 | This can be done by defining a property group project named `FodyDependsOnTargets`. The content of this property will then be passed to the `DependsOnTargets` of the Fody weaving task. 165 | 166 | > DependsOnTargets: The targets that must be executed before this target can be executed or top-level dependency analysis can occur. Multiple targets are separated by semicolons. 167 | 168 | An example use case of this is to force Fody to run after [CodeContracts](https://docs.microsoft.com/en-us/dotnet/framework/debug-trace-profile/code-contracts). 169 | 170 | ```xml 171 | 172 | 173 | CodeContractRewrite 174 | 175 | 176 | ``` 177 | 178 | 179 | ## Assembly verification 180 | 181 | Post build verification via [PeVerify](https://docs.microsoft.com/en-us/dotnet/framework/tools/peverify-exe-peverify-tool) is supported. 182 | 183 | To enable do one of the following 184 | 185 | Add `VerifyAssembly="true"` to FodyWeavers.xml: 186 | 187 | ```xml 188 | 189 | 190 | 191 | ``` 192 | 193 | Add a build constant with the value of `FodyVerifyAssembly` 194 | 195 | To send ignore codes to PeVerify use `VerifyIgnoreCodes`. 196 | 197 | ```xml 198 | 200 | 201 | 202 | ``` 203 | -------------------------------------------------------------------------------- /pages/mdsource/addins.source.md: -------------------------------------------------------------------------------- 1 | # Addins List 2 | 3 | * [Anotar](https://github.com/Fody/Anotar) Simplifies logging through a static class and some IL manipulation. 4 | * [AsyncErrorHandler](https://github.com/Fody/AsyncErrorHandler) Integrates error handling into async and TPL code. 5 | * [AutoProperties](https://github.com/tom-englert/AutoProperties.Fody) Extends control over auto-properties, like directly accessing the backing field or intercepting getters and setters. 6 | * [BasicFodyAddin](/BasicFodyAddin) Used to illustrate how to build an addin. 7 | * [Bindables](https://github.com/yusuf-gunaydin/Bindables) Converts auto properties into Wpf dependency or attached properties. Allows specifying options, defining readonly properties, and calling property changed methods. 8 | * [Caseless](https://github.com/Fody/Caseless) Change string comparisons to be case insensitive. 9 | * [Catel](https://github.com/Catel/Catel.Fody) For transforming automatic properties into [Catel](https://github.com/Catel/Catel) properties. 10 | * [ConfigureAwait](https://github.com/Fody/ConfigureAwait) Set the async ConfigureAwait at a global level for all await calls. 11 | * [Costura](https://github.com/Fody/Costura/) For embedding references as resources. 12 | * [EmptyConstructor](https://github.com/Fody/EmptyConstructor) Adds an empty constructor to classes even if a non empty one is defined. 13 | * [Equals](https://github.com/Fody/Equals) Generate Equals, GetHashCode and operators methods from properties. 14 | * [Equatable](https://github.com/tom-englert/Equatable.Fody) Generate Equals, GetHashCode and operators methods from explicit annotated fields and properties. 15 | * [ExtraConstraints](https://github.com/Fody/ExtraConstraints) Facilitates adding constraints for Enum and Delegate to types and methods. 16 | * [InfoOf](https://github.com/Fody/InfoOf) Provides `methodof`, `propertyof` and `fieldof` equivalents of [`typeof`](https://msdn.microsoft.com/en-us/library/58918ffs.aspx). 17 | * [InlineIL](https://github.com/ltrzesniewski/InlineIL.Fody) Provides a way to embed arbitrary IL instructions in existing code. 18 | * [Ionad](https://github.com/Fody/Ionad) Replaces static method calls. 19 | * [Janitor](https://github.com/Fody/Janitor) Simplifies the implementation of [IDisposable](https://docs.microsoft.com/en-us/dotnet/api/system.idisposable). 20 | * [JetBrainsAnnotations](https://github.com/tom-englert/JetBrainsAnnotations.Fody) Converts all JetBrains ReSharper code annotation attributes to External Annotations. 21 | * [Lazy](https://github.com/tom-englert/Lazy.Fody) Automates the plumbing around System.Lazy. 22 | * [LoadAssembliesOnStartup](https://github.com/Fody/LoadAssembliesOnStartup) Loads references on startup by using the types in the module initializer. 23 | * [LocalsInit](https://github.com/ltrzesniewski/LocalsInit.Fody) Controls the value of the `localsinit` flag on methods, to improve the performance of `stackalloc` for instance. 24 | * [LoggerIsEnabled](https://github.com/wazowsk1/LoggerIsEnabled.Fody) Adds `ILogger.IsEnabled` check around the logging statement for the [Microsoft.Extensions.Logging](https://github.com/aspnet/Logging). 25 | * [MethodBoundaryAspect](https://github.com/vescon/MethodBoundaryAspect.Fody) Allows to decorate methods and hook into method start, method end and method exceptions (like PostSharp). 26 | * [MethodDecorator](https://github.com/Fody/MethodDecorator) Decorate arbitrary methods to run code before and after invocation. 27 | * [MethodTimer](https://github.com/Fody/MethodTimer) Injects method timing code. 28 | * [ModuleInit](https://github.com/Fody/ModuleInit) Adds a module initializer to an assembly. 29 | * [NullGuard](https://github.com/Fody/NullGuard) Adds null argument checks to an assembly. 30 | * [Obsolete](https://github.com/Fody/Obsolete) Helps keep usages of [ObsoleteAttribute]([https://msdn.microsoft.com/en-us/library/fwz0y5c2 ) consistent. 31 | * [PropertyChanged](https://github.com/Fody/PropertyChanged) Injects INotifyPropertyChanged code into properties. 32 | * [PropertyChanging](https://github.com/Fody/PropertyChanging) Injects INotifyPropertyChanging code into properties. 33 | * [Publicize](https://github.com/Fody/Publicize) Converts non-public members to public hidden members. 34 | * [ReactiveUI.Fody](https://github.com/reactiveui/ReactiveUI) Generates [ReactiveUI](https://reactiveui.net/) `RaisePropertyChanged` notifications for properties and `OAPH`s. 35 | * [Resourcer](https://github.com/Fody/Resourcer) Simplifies reading embedded resources from an Assembly. 36 | * [RuntimeNullables](https://github.com/Singulink/RuntimeNullables) Runtime C# 8+ Nullable Reference Type (NRT) contract validation. 37 | * [Someta](https://github.com/kswoll/someta) Offers the ability to intercept methods, properties, and events; inject fields into classes; and inject code inside constructors. 38 | * [SplashScreen](https://github.com/tom-englert/SplashScreen.Fody) Use WPF splash screen as a WPF Control instead of a static bitmap. 39 | * [StampSvn](https://github.com/krk/Stamp) Stamps an assembly with SVN data. 40 | * [Substitute](https://github.com/tom-englert/Substitute.Fody) Substitute types with other types to e.g. intercept generated code. 41 | * [SwallowExceptions](https://github.com/duaneedwards/SwallowExceptions) Swallow Exceptions in targeted methods. 42 | * [Throttle](https://github.com/tom-englert/Throttle.Fody) Easily use throttles with minimal coding. 43 | * [ToString](https://github.com/Fody/ToString) Generate `ToString` method from public properties. 44 | * [Tracer](https://github.com/csnemes/tracer) Adds trace-enter and trace-leave log entries for selected methods. 45 | * [Undisposed](https://github.com/ermshiperete/undisposed-fody) Debugging tool to track down undisposed objects. 46 | * [Validar](https://github.com/Fody/Validar) Injects [IDataErrorInfo](https://docs.microsoft.com/en-us/dotnet/api/system.componentmodel.idataerrorinfo) or [INotifyDataErrorInfo](https://docs.microsoft.com/en-us/dotnet/api/system.componentmodel.inotifydataerrorinfo) code into a class at compile time. 47 | * [Vandelay](https://github.com/jasonwoods-7/Vandelay) Simplifies MEF importing\exporting. 48 | * [Visualize](https://github.com/Fody/Visualize) Adds debugger attributes to help visualize objects. 49 | * [Virtuosity](https://github.com/Fody/Virtuosity) Change all members to virtual. 50 | * [WeakEventHandler](https://github.com/tom-englert/WeakEventHandler.Fody) Changes regular event handlers into weak event handlers by weaving a weak event adapter between source and subscriber. 51 | * [WeakEvents](https://github.com/adbancroft/WeakEvents.Fody) Automatic publishing of weak events via compile time code weaving and a supporting runtime library. 52 | * [With](https://github.com/mikhailshilkov/With.Fody) Methods to return copies of immutable objects with one property modified. 53 | 54 | 55 | ## No longer maintained 56 | 57 | The below addins are no longer maintained. Raise an issue in the specific project to take ownership. 58 | 59 | * [ArraySlice](https://github.com/Codealike/arrayslice) ArraySlice allows to build shared memory array views without performance impact. It uses IL manipulation to achieve the fastest implementation. 60 | * [AssertMessage](https://github.com/Fody/AssertMessage) Generates 'message' from sourcecode and adds it to assertion. 61 | * [AutoDependencyProperty](http://blog.angeloflogic.com/2014/12/no-more-dependencyproperty-with.html) Generates WPF DependencyProperty boilerplate from automatic C# properties. 62 | * [AutoLazy](https://github.com/bcuff/AutoLazy) Automatically implements the double-checked locking pattern on specified properties and methods. 63 | * [Cauldron](https://github.com/Capgemini/Cauldron) Provides method, property and field interception. It also provides weavers for Cauldron.Core and Cauldron.Activator. 64 | * [Cilador](https://github.com/rileywhite/Cilador) Write [mixins](https://en.wikipedia.org/wiki/Mixin) in C# for code reuse without inheritance. 65 | * [Commander](https://github.com/DamianReeves/Commander.Fody) Injects ICommand properties and implementations for use in MVVM applications. 66 | * [CryptStr](https://cryptstr.codeplex.com/) Encrypts literal strings in .NET assemblies. 67 | * [DependencyInjection](https://github.com/jorgehmv/FodyDependencyInjection) automatic dependency injection for [Ninject](http://www.ninject.org/), [Autofac](http://autofac.org/) and [Spring](http://www.springframework.net/). 68 | * [EmptyStringGuard](https://github.com/thirkcircus/EmptyStringGuard) Adds empty string argument checks to an assembly. 69 | * [EnableFaking](https://github.com/philippdolder/EnableFaking.Fody) Allows faking types without writing interfaces for testing purposes only. 70 | * [Expose](https://github.com/kedarvaidya/Expose.Fody) Exposes members and optionally implements interface of a field declared in class. 71 | * [FactoryId](https://github.com/ramoneeza/FactoryId.Fody) Simplifies the implementation of Factory Method Pattern. 72 | * [Fielder](https://github.com/fodyarchived/Fielder) Converts public fields to public properties. 73 | * [Freezable](https://github.com/fodyarchived/Freezable) Implements the Freezable pattern. 74 | * [Immutable](https://github.com/fodyarchived/Immutable) Creates immutable types. 75 | * [MethodCache](https://github.com/Dresel/MethodCache) Caches return values of methods decorated with a `CacheAttribute`. 76 | * [Mixins](https://bitbucket.org/skwasiborski/mixins.fody/wiki/Home) A mixin is a class that provides a certain functionality to be inherited or reused by a subclass. 77 | * [Mutable](https://github.com/ndamjan/Mutable.Fody) Make F# setters for union types and eliminate need for `CLIMutable` attribute for records. 78 | * [Mvid](https://github.com/hmemcpy/Mvid.Fody) Adds the ability to specify the assembly MVID (Module Version Id). 79 | * [NameOf](https://github.com/NickStrupat/NameOf) Provides strongly typed access to a compile-time string representing the name of a variable, field, property, method, event, enum value, or type. 80 | * [Nancy.ModelPostprocess](https://bitbucket.org/tpluscode/nancy.modelpostprocess) Modify Nancy models after route execution but before serialization 81 | * [NObservable](https://github.com/kekekeks/NObservable) MobX-like observable state management library with Blazor support. 82 | * [Padded](https://github.com/Scooletz/Padded) Adds padding to fight the false sharing problem. 83 | * [QueryValidator](https://github.com/kamil-mrzyglod/QueryValidator.Fody) Validates DB queries during a build. 84 | * [RemoveReference](https://github.com/icnocop/RemoveReference.Fody) Facilitates removing references in a compiled assembly during a build. 85 | * [RomanticWeb](http://romanticweb.net/) Fody weaver plugin for RomanticWeb instrumentation. 86 | * [Scalpel](https://github.com/Fody/Scalpel) Strips tests from an assembly. 87 | * [Seal](https://github.com/kamil-mrzyglod/Seal) mark all non-virtual(abstract, non-sealed) types as sealed by default. 88 | * [SexyProxy](https://github.com/kswoll/sexy-proxy) Proxy generator with support for async patterns. 89 | * [Spring](https://github.com/jorgehmv/FodySpring) Spring constructor configuration. 90 | * [Stamp](https://github.com/304NotModified/Fody.Stamp) Stamps an assembly with git data. 91 | * [StaticProxy](https://github.com/BrunoJuchli/StaticProxy.Fody) Proxy Generator, also for .net standard / .net core (.net standard 1.0+). 92 | * [Stiletto](https://github.com/benjamin-bader/stiletto) Compile-time static analysis and optimization for the Stiletto IoC library. 93 | * [Tail](https://github.com/hazzik/Tail.Fody) Adds a postfixed method call instruction to recursive calls. 94 | * [TestFlask](https://github.com/FatihSahin/test-flask) Records method args and responses to replay, assert and test. 95 | * [Unsealed](https://github.com/fodyarchived/Unsealed) A Fody weaver to unseal sealed types. 96 | * [Usable](https://github.com/fodyarchived/Usable) Adds using statements for local variables that have been created, and implement [IDisposable](https://docs.microsoft.com/en-us/dotnet/api/system.idisposable). 97 | * [YALF](https://github.com/sharpmonkey/YALF) Yet Another Logging Framework. 98 | -------------------------------------------------------------------------------- /pages/mdsource/addin-development.source.md: -------------------------------------------------------------------------------- 1 | # Addin development 2 | 3 | This page uses the a sample addin called BasicFodyAddin to describe building an addin. 4 | 5 | * [NuGet Package](https://www.nuget.org/packages/BasicFodyAddin.Fody/) 6 | * [Source](/BasicFodyAddin/) 7 | 8 | 9 | ## Lib/Reference project 10 | 11 | [BasicFodyAddin.csproj](/BasicFodyAddin/BasicFodyAddin/) 12 | 13 | * Contain all classes to control the addin behavior at compile time or provide intellisense to consumers. Often this is in the form of [Attributes](https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/attributes/). 14 | * Generally any usage and reference to this project is removed at compile time so it is not needed as part of application deployment. 15 | * The target frameworks depends on what targets the weaver can support (see [Supported Runtimes And Ide](supported-runtimes-and-ide.md)). 16 | 17 | This project is also used to produce the NuGet package. To achieve this the project consumes two NuGets: 18 | 19 | * [Fody](https://www.nuget.org/packages/Fody/) with `PrivateAssets="None"`. This results in producing NuGet package having a dependency on Fody with all `include="All"` in the nuspec. Note that while this project consumes the Fody NuGet, weaving is not performed on this project. This is due to the FodyPackaging NuGet (see below) including `true` in the MSBuild pipeline. 20 | * [FodyPackaging](addin-packaging.md#fodypackaging-nuget-package) with `PrivateAssets="All"`. This results in a NuGet package being produced by this project, but no dependency on FodyPackaging in the resulting NuGet package. 21 | 22 | The produced NuGet package will: 23 | 24 | * Be named with `.Fody` suffix. This project should also contain all appropriate [NuGet metadata properties](https://docs.microsoft.com/en-us/dotnet/core/tools/csproj#nuget-metadata-properties). Many of these properties have defaults in [FodyPackaging](https://github.com/Fody/Fody/blob/master/FodyPackaging/build/FodyPackaging.props), but can be overridden. 25 | * Target, and hence support from a consumer perspective, the same frameworks that this project targets. 26 | * Be created in a directory named `nugets` at the root of the solution. 27 | 28 | snippet: BasicFodyAddin.csproj 29 | 30 | 31 | ### Build Order 32 | 33 | The Lib/Reference project must contain a [Project Dependency](https://docs.microsoft.com/en-us/visualstudio/ide/how-to-create-and-remove-project-dependencies?view=vs-2019) on the [Weaver-Project](Weaver-Project) to ensure it is built after the Weaver Project produces its output. 34 | 35 | ![project dependencies](project-dependencies.png) 36 | 37 | If a weaver file cannot be found, the build will fail with one of the following: 38 | 39 | > FodyPackaging: No weaver found at [PATH]. BasicFodyAddin should have a Project Dependency on BasicFodyAddin.Fody. 40 | 41 | 42 | ## Weaver Project 43 | 44 | [BasicFodyAddin.Fody.csproj](/BasicFodyAddin/BasicFodyAddin.Fody/) 45 | 46 | This project contains the weaving code. 47 | 48 | * Has a NuGet dependency on [FodyHelpers](https://www.nuget.org/packages/FodyHelpers/). 49 | * Should not have any runtime dependencies (excluding Mono Cecil); runtime dependencies should be combined using e.g. [ILMerge](https://github.com/dotnet/ILMerge) and the `/Internalize` flag. 50 | * The assembly must contain a public class named 'ModuleWeaver'. The namespace does not matter. 51 | 52 | snippet: BasicFodyAddin.Fody.csproj 53 | 54 | 55 | ### Target Frameworks 56 | 57 | This project must target `netstandard2.0`. 58 | 59 | 60 | ### Output of the project 61 | 62 | It outputs a file named `BasicFodyAddin.Fody`. The '.Fody' suffix is necessary to be picked up by Fody at compile time. 63 | 64 | 65 | ### ModuleWeaver 66 | 67 | ModuleWeaver.cs is where the target assembly is modified. Fody will pick up this type during its processing. Note that the class must be named as `ModuleWeaver`. 68 | 69 | `ModuleWeaver` must use the base class of `BaseModuleWeaver` which exists in the [FodyHelpers NuGet](https://www.nuget.org/packages/FodyHelpers/). 70 | 71 | * Inherit from `BaseModuleWeaver`. 72 | * The class must be public, non static, and not abstract. 73 | * Have an empty constructor. 74 | 75 | snippet: ModuleWeaver 76 | 77 | 78 | #### BaseModuleWeaver.Execute 79 | 80 | Called to perform the manipulation of the module. The current module can be accessed and manipulated via `BaseModuleWeaver.ModuleDefinition`. 81 | 82 | snippet: Execute 83 | 84 | 85 | #### Resultant injected code 86 | 87 | In this case a new type is being injected into the target assembly that looks like this. 88 | 89 | ```csharp 90 | public class Hello 91 | { 92 | public string World() 93 | { 94 | return "Hello World"; 95 | } 96 | } 97 | ``` 98 | 99 | 100 | #### BaseModuleWeaver.GetAssembliesForScanning 101 | 102 | Called by Fody when it is building up a type cache for lookups. This method should return all possible assemblies that the weaver may require while resolving types. In this case BasicFodyAddin requires `System.Object`, so `GetAssembliesForScanning` returns `netstandard` and `mscorlib`. It is safe to return assembly names that are not used by the current target assembly as these will be ignored. 103 | 104 | To use this type cache, a `ModuleWeaver` can call `BaseModuleWeaver.FindType` within `Execute` method. 105 | 106 | snippet: GetAssembliesForScanning 107 | 108 | 109 | #### BaseModuleWeaver.ShouldCleanReference 110 | 111 | When `BasicFodyAddin.dll` is referenced by a consuming project, it is only for the purposes configuring the weaving via attributes. As such, it is not required at runtime. With this in mind `BaseModuleWeaver` has an opt in feature to remove the reference, meaning the target weaved application does not need `BasicFodyAddin.dll` at runtime. This feature can be opted in to via the following code in `ModuleWeaver`: 112 | 113 | snippet: ShouldCleanReference 114 | 115 | 116 | #### Logging 117 | 118 | Many helpers exist for writing log entries to MSBuild: 119 | 120 | snippet: MyLoggingWeaver.cs 121 | 122 | 123 | #### Other BaseModuleWeaver Members 124 | 125 | `BaseModuleWeaver` has other members for extensibility: 126 | https://github.com/Fody/Fody/blob/master/FodyHelpers/BaseModuleWeaver.cs 127 | 128 | 129 | ### Throwing exceptions 130 | 131 | When writing an addin there are a points to note when throwing an Exception. 132 | 133 | * Exceptions thrown from an addin will be caught and interpreted as a build error. So this will stop the build. 134 | * The exception information will be logged to the MSBuild `BuildEngine.LogErrorEvent` method. 135 | * If the exception type is `WeavingException` then it will be interpreted as an "error". So the addin is explicitly throwing an exception with the intent of stopping processing and logging a message to the build log. In this case the message logged will be the contents of `WeavingException.Message` property. If the `WeavingException` has a property `SequencePoint` then that information will be passed to the build engine so a user can navigate to the error. 136 | * If the exception type is *not* a `WeavingException` then it will be interpreted as an "unhandled exception". So something has gone seriously wrong with the addin. It most likely has a bug. In this case message logged be much bore verbose and will contain the full contents of the Exception. The code for getting the message can be found here in [ExceptionExtensions](https://github.com/Fody/Fody/blob/master/FodyCommon/ExceptionExtensions.cs). 137 | 138 | 139 | ## Passing config via to FodyWeavers.xml 140 | 141 | This file exists at a project level in the users target project and is used to pass configuration to the 'ModuleWeaver'. 142 | 143 | So if the FodyWeavers.xml file contains the following: 144 | 145 | ```xml 146 | 147 | 148 | 149 | ``` 150 | 151 | The property of the `ModuleWeaver.Config` will be an [XElement](https://docs.microsoft.com/en-us/dotnet/api/system.xml.linq.xelement) containing: 152 | 153 | ```xml 154 | 155 | ``` 156 | 157 | 158 | ### Supporting intellisense for FodyWeavers.xml 159 | 160 | Fody will create or update a schema file (FodyWeavers.xsd) for every FodyWeavers.xml during compilation, adding all detected weavers. Every weaver now can provide a schema fragment describing it's individual properties and content that can be set. This file must be part of the weaver project and named `.xcf`. It contains the element describing the type of the configuration node. The file must be published side by side with the weaver file; however [FodyPackaging](fodypackaging.md) will configure this correctly based on the convention `WeaverName.Fody.xcf`. 161 | 162 | Sample content of the `BasicFodyAddin.Fody.xcf`: 163 | 164 | snippet: BasicFodyAddin.Fody.Xcf 165 | 166 | Fody will then combine all `.xcf` fragments with the weavers information to the final `.xsd`: 167 | 168 | snippet: FodyWeavers.xsd 169 | 170 | 171 | ## AssemblyToProcess Project 172 | 173 | [AssemblyToProcess.csproj](/BasicFodyAddin/AssemblyToProcess/) 174 | 175 | A target assembly to process and then validate with unit tests. 176 | 177 | 178 | ## Tests Project 179 | 180 | [Tests.csproj](/BasicFodyAddin/Tests/) 181 | 182 | Contains all tests for the weaver. 183 | 184 | The project has a NuGet dependency on [FodyHelpers](https://www.nuget.org/packages/FodyHelpers/). 185 | 186 | It has a reference to the `AssemblyToProcess` project, so that `AssemblyToProcess.dll` is copied to the bin directory of the test project. 187 | 188 | FodyHelpers contains a utility [WeaverTestHelper](https://github.com/Fody/Fody/blob/master/FodyHelpers/Testing/WeaverTestHelper.cs) for executing test runs on a target assembly using a ModuleWeaver. 189 | 190 | A test can then be run as follows: 191 | 192 | snippet: WeaverTests 193 | 194 | By default `ExecuteTestRun` will perform a [PeVerify](https://docs.microsoft.com/en-us/dotnet/framework/tools/peverify-exe-peverify-tool) on the resultant assembly. 195 | 196 | snippet: Tests.csproj 197 | 198 | 199 | ## Build Server 200 | 201 | 202 | ### AppVeyor 203 | 204 | To configure an adding to build using [AppVeyor](https://www.appveyor.com/) use the following `appveyor.yml`: 205 | 206 | snippet: appveyor.yml 207 | 208 | 209 | ## Usage 210 | 211 | 212 | ### NuGet installation 213 | 214 | Install the [BasicFodyAddin.Fody NuGet package](https://www.nuget.org/packages/BasicFodyAddin.Fody/) and update the [Fody NuGet package](https://www.nuget.org/packages/Fody/): 215 | 216 | ```powershell 217 | PM> Install-Package Fody 218 | PM> Install-Package BasicFodyAddin.Fody 219 | ``` 220 | 221 | The `Install-Package Fody` is required since NuGet always defaults to the oldest, and most buggy, version of any dependency. 222 | 223 | 224 | ### Add to FodyWeavers.xml 225 | 226 | ```xml 227 | 228 | 229 | 230 | ``` 231 | 232 | 233 | ## Deployment 234 | 235 | Addins are deployed through [NuGet](https://www.nuget.org/) packages. The package must: 236 | 237 | * Contain two weaver assemblies, one in each of the folders `netclassicweaver` and `netstandardweaver`, to support both .Net Classic and .Net Core. 238 | * Contain a runtime library, compiled for every supported framework, under the `lib` folder. 239 | * Contain an MsBuild .props file in the `build` folder that registers the weaver at compile time. The name of the file must be the package id with the `.props` extension. See [Addin Discover](addin-discovery.md) for details. 240 | * Have an id with the same name of the weaver assembly should be the same and be suffixed with ".Fody". So in this case the [BasicFodyAddin.Fody NuGet](https://www.nuget.org/packages/BasicFodyAddin.Fody/) contains the weaver assembly `BasicFodyAddin.Fody.dll` and the reference assembly `BasicFodyAddin.dll`. 241 | * Have a single dependency on **only** the [Fody NuGet package](https://www.nuget.org/packages/Fody/). **Do not add any other NuGet dependencies as Fody does not support loading these files at compile time.** 242 | 243 | Note that the addins used via [in-solution-weaving](in-solution-weaving.md) are handled differently. -------------------------------------------------------------------------------- /pages/addins.md: -------------------------------------------------------------------------------- 1 | 7 | 8 | # Addins List 9 | 10 | * [Anotar](https://github.com/Fody/Anotar) Simplifies logging through a static class and some IL manipulation. 11 | * [AsyncErrorHandler](https://github.com/Fody/AsyncErrorHandler) Integrates error handling into async and TPL code. 12 | * [AutoProperties](https://github.com/tom-englert/AutoProperties.Fody) Extends control over auto-properties, like directly accessing the backing field or intercepting getters and setters. 13 | * [BasicFodyAddin](/BasicFodyAddin) Used to illustrate how to build an addin. 14 | * [Bindables](https://github.com/yusuf-gunaydin/Bindables) Converts auto properties into Wpf dependency or attached properties. Allows specifying options, defining readonly properties, and calling property changed methods. 15 | * [Caseless](https://github.com/Fody/Caseless) Change string comparisons to be case insensitive. 16 | * [Catel](https://github.com/Catel/Catel.Fody) For transforming automatic properties into [Catel](https://github.com/Catel/Catel) properties. 17 | * [ConfigureAwait](https://github.com/Fody/ConfigureAwait) Set the async ConfigureAwait at a global level for all await calls. 18 | * [Costura](https://github.com/Fody/Costura/) For embedding references as resources. 19 | * [EmptyConstructor](https://github.com/Fody/EmptyConstructor) Adds an empty constructor to classes even if a non empty one is defined. 20 | * [Equals](https://github.com/Fody/Equals) Generate Equals, GetHashCode and operators methods from properties. 21 | * [Equatable](https://github.com/tom-englert/Equatable.Fody) Generate Equals, GetHashCode and operators methods from explicit annotated fields and properties. 22 | * [ExtraConstraints](https://github.com/Fody/ExtraConstraints) Facilitates adding constraints for Enum and Delegate to types and methods. 23 | * [InfoOf](https://github.com/Fody/InfoOf) Provides `methodof`, `propertyof` and `fieldof` equivalents of [`typeof`](https://msdn.microsoft.com/en-us/library/58918ffs.aspx). 24 | * [InlineIL](https://github.com/ltrzesniewski/InlineIL.Fody) Provides a way to embed arbitrary IL instructions in existing code. 25 | * [Ionad](https://github.com/Fody/Ionad) Replaces static method calls. 26 | * [Janitor](https://github.com/Fody/Janitor) Simplifies the implementation of [IDisposable](https://docs.microsoft.com/en-us/dotnet/api/system.idisposable). 27 | * [JetBrainsAnnotations](https://github.com/tom-englert/JetBrainsAnnotations.Fody) Converts all JetBrains ReSharper code annotation attributes to External Annotations. 28 | * [Lazy](https://github.com/tom-englert/Lazy.Fody) Automates the plumbing around System.Lazy. 29 | * [LoadAssembliesOnStartup](https://github.com/Fody/LoadAssembliesOnStartup) Loads references on startup by using the types in the module initializer. 30 | * [LocalsInit](https://github.com/ltrzesniewski/LocalsInit.Fody) Controls the value of the `localsinit` flag on methods, to improve the performance of `stackalloc` for instance. 31 | * [LoggerIsEnabled](https://github.com/wazowsk1/LoggerIsEnabled.Fody) Adds `ILogger.IsEnabled` check around the logging statement for the [Microsoft.Extensions.Logging](https://github.com/aspnet/Logging). 32 | * [MethodBoundaryAspect](https://github.com/vescon/MethodBoundaryAspect.Fody) Allows to decorate methods and hook into method start, method end and method exceptions (like PostSharp). 33 | * [MethodDecorator](https://github.com/Fody/MethodDecorator) Decorate arbitrary methods to run code before and after invocation. 34 | * [MethodTimer](https://github.com/Fody/MethodTimer) Injects method timing code. 35 | * [ModuleInit](https://github.com/Fody/ModuleInit) Adds a module initializer to an assembly. 36 | * [NullGuard](https://github.com/Fody/NullGuard) Adds null argument checks to an assembly. 37 | * [Obsolete](https://github.com/Fody/Obsolete) Helps keep usages of [ObsoleteAttribute]([https://msdn.microsoft.com/en-us/library/fwz0y5c2 ) consistent. 38 | * [PropertyChanged](https://github.com/Fody/PropertyChanged) Injects INotifyPropertyChanged code into properties. 39 | * [PropertyChanging](https://github.com/Fody/PropertyChanging) Injects INotifyPropertyChanging code into properties. 40 | * [Publicize](https://github.com/Fody/Publicize) Converts non-public members to public hidden members. 41 | * [ReactiveUI.Fody](https://github.com/reactiveui/ReactiveUI) Generates [ReactiveUI](https://reactiveui.net/) `RaisePropertyChanged` notifications for properties and `OAPH`s. 42 | * [Resourcer](https://github.com/Fody/Resourcer) Simplifies reading embedded resources from an Assembly. 43 | * [RuntimeNullables](https://github.com/Singulink/RuntimeNullables) Runtime C# 8+ Nullable Reference Type (NRT) contract validation. 44 | * [Someta](https://github.com/kswoll/someta) Offers the ability to intercept methods, properties, and events; inject fields into classes; and inject code inside constructors. 45 | * [SplashScreen](https://github.com/tom-englert/SplashScreen.Fody) Use WPF splash screen as a WPF Control instead of a static bitmap. 46 | * [StampSvn](https://github.com/krk/Stamp) Stamps an assembly with SVN data. 47 | * [Substitute](https://github.com/tom-englert/Substitute.Fody) Substitute types with other types to e.g. intercept generated code. 48 | * [SwallowExceptions](https://github.com/duaneedwards/SwallowExceptions) Swallow Exceptions in targeted methods. 49 | * [Throttle](https://github.com/tom-englert/Throttle.Fody) Easily use throttles with minimal coding. 50 | * [ToString](https://github.com/Fody/ToString) Generate `ToString` method from public properties. 51 | * [Tracer](https://github.com/csnemes/tracer) Adds trace-enter and trace-leave log entries for selected methods. 52 | * [Undisposed](https://github.com/ermshiperete/undisposed-fody) Debugging tool to track down undisposed objects. 53 | * [Validar](https://github.com/Fody/Validar) Injects [IDataErrorInfo](https://docs.microsoft.com/en-us/dotnet/api/system.componentmodel.idataerrorinfo) or [INotifyDataErrorInfo](https://docs.microsoft.com/en-us/dotnet/api/system.componentmodel.inotifydataerrorinfo) code into a class at compile time. 54 | * [Vandelay](https://github.com/jasonwoods-7/Vandelay) Simplifies MEF importing\exporting. 55 | * [Visualize](https://github.com/Fody/Visualize) Adds debugger attributes to help visualize objects. 56 | * [Virtuosity](https://github.com/Fody/Virtuosity) Change all members to virtual. 57 | * [WeakEventHandler](https://github.com/tom-englert/WeakEventHandler.Fody) Changes regular event handlers into weak event handlers by weaving a weak event adapter between source and subscriber. 58 | * [WeakEvents](https://github.com/adbancroft/WeakEvents.Fody) Automatic publishing of weak events via compile time code weaving and a supporting runtime library. 59 | * [With](https://github.com/mikhailshilkov/With.Fody) Methods to return copies of immutable objects with one property modified. 60 | 61 | 62 | ## No longer maintained 63 | 64 | The below addins are no longer maintained. Raise an issue in the specific project to take ownership. 65 | 66 | * [ArraySlice](https://github.com/Codealike/arrayslice) ArraySlice allows to build shared memory array views without performance impact. It uses IL manipulation to achieve the fastest implementation. 67 | * [AssertMessage](https://github.com/Fody/AssertMessage) Generates 'message' from sourcecode and adds it to assertion. 68 | * [AutoDependencyProperty](http://blog.angeloflogic.com/2014/12/no-more-dependencyproperty-with.html) Generates WPF DependencyProperty boilerplate from automatic C# properties. 69 | * [AutoLazy](https://github.com/bcuff/AutoLazy) Automatically implements the double-checked locking pattern on specified properties and methods. 70 | * [Cauldron](https://github.com/Capgemini/Cauldron) Provides method, property and field interception. It also provides weavers for Cauldron.Core and Cauldron.Activator. 71 | * [Cilador](https://github.com/rileywhite/Cilador) Write [mixins](https://en.wikipedia.org/wiki/Mixin) in C# for code reuse without inheritance. 72 | * [Commander](https://github.com/DamianReeves/Commander.Fody) Injects ICommand properties and implementations for use in MVVM applications. 73 | * [CryptStr](https://cryptstr.codeplex.com/) Encrypts literal strings in .NET assemblies. 74 | * [DependencyInjection](https://github.com/jorgehmv/FodyDependencyInjection) automatic dependency injection for [Ninject](http://www.ninject.org/), [Autofac](http://autofac.org/) and [Spring](http://www.springframework.net/). 75 | * [EmptyStringGuard](https://github.com/thirkcircus/EmptyStringGuard) Adds empty string argument checks to an assembly. 76 | * [EnableFaking](https://github.com/philippdolder/EnableFaking.Fody) Allows faking types without writing interfaces for testing purposes only. 77 | * [Expose](https://github.com/kedarvaidya/Expose.Fody) Exposes members and optionally implements interface of a field declared in class. 78 | * [FactoryId](https://github.com/ramoneeza/FactoryId.Fody) Simplifies the implementation of Factory Method Pattern. 79 | * [Fielder](https://github.com/fodyarchived/Fielder) Converts public fields to public properties. 80 | * [Freezable](https://github.com/fodyarchived/Freezable) Implements the Freezable pattern. 81 | * [Immutable](https://github.com/fodyarchived/Immutable) Creates immutable types. 82 | * [MethodCache](https://github.com/Dresel/MethodCache) Caches return values of methods decorated with a `CacheAttribute`. 83 | * [Mixins](https://bitbucket.org/skwasiborski/mixins.fody/wiki/Home) A mixin is a class that provides a certain functionality to be inherited or reused by a subclass. 84 | * [Mutable](https://github.com/ndamjan/Mutable.Fody) Make F# setters for union types and eliminate need for `CLIMutable` attribute for records. 85 | * [Mvid](https://github.com/hmemcpy/Mvid.Fody) Adds the ability to specify the assembly MVID (Module Version Id). 86 | * [NameOf](https://github.com/NickStrupat/NameOf) Provides strongly typed access to a compile-time string representing the name of a variable, field, property, method, event, enum value, or type. 87 | * [Nancy.ModelPostprocess](https://bitbucket.org/tpluscode/nancy.modelpostprocess) Modify Nancy models after route execution but before serialization 88 | * [NObservable](https://github.com/kekekeks/NObservable) MobX-like observable state management library with Blazor support. 89 | * [Padded](https://github.com/Scooletz/Padded) Adds padding to fight the false sharing problem. 90 | * [QueryValidator](https://github.com/kamil-mrzyglod/QueryValidator.Fody) Validates DB queries during a build. 91 | * [RemoveReference](https://github.com/icnocop/RemoveReference.Fody) Facilitates removing references in a compiled assembly during a build. 92 | * [RomanticWeb](http://romanticweb.net/) Fody weaver plugin for RomanticWeb instrumentation. 93 | * [Scalpel](https://github.com/Fody/Scalpel) Strips tests from an assembly. 94 | * [Seal](https://github.com/kamil-mrzyglod/Seal) mark all non-virtual(abstract, non-sealed) types as sealed by default. 95 | * [SexyProxy](https://github.com/kswoll/sexy-proxy) Proxy generator with support for async patterns. 96 | * [Spring](https://github.com/jorgehmv/FodySpring) Spring constructor configuration. 97 | * [Stamp](https://github.com/304NotModified/Fody.Stamp) Stamps an assembly with git data. 98 | * [StaticProxy](https://github.com/BrunoJuchli/StaticProxy.Fody) Proxy Generator, also for .net standard / .net core (.net standard 1.0+). 99 | * [Stiletto](https://github.com/benjamin-bader/stiletto) Compile-time static analysis and optimization for the Stiletto IoC library. 100 | * [Tail](https://github.com/hazzik/Tail.Fody) Adds a postfixed method call instruction to recursive calls. 101 | * [TestFlask](https://github.com/FatihSahin/test-flask) Records method args and responses to replay, assert and test. 102 | * [Unsealed](https://github.com/fodyarchived/Unsealed) A Fody weaver to unseal sealed types. 103 | * [Usable](https://github.com/fodyarchived/Usable) Adds using statements for local variables that have been created, and implement [IDisposable](https://docs.microsoft.com/en-us/dotnet/api/system.idisposable). 104 | * [YALF](https://github.com/sharpmonkey/YALF) Yet Another Logging Framework. 105 | -------------------------------------------------------------------------------- /images/particular.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /pages/addin-development.md: -------------------------------------------------------------------------------- 1 | 7 | 8 | # Addin development 9 | 10 | This page uses the a sample addin called BasicFodyAddin to describe building an addin. 11 | 12 | * [NuGet Package](https://www.nuget.org/packages/BasicFodyAddin.Fody/) 13 | * [Source](/BasicFodyAddin/) 14 | 15 | 16 | ## Lib/Reference project 17 | 18 | [BasicFodyAddin.csproj](/BasicFodyAddin/BasicFodyAddin/) 19 | 20 | * Contain all classes to control the addin behavior at compile time or provide intellisense to consumers. Often this is in the form of [Attributes](https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/attributes/). 21 | * Generally any usage and reference to this project is removed at compile time so it is not needed as part of application deployment. 22 | * The target frameworks depends on what targets the weaver can support (see [Supported Runtimes And Ide](supported-runtimes-and-ide.md)). 23 | 24 | This project is also used to produce the NuGet package. To achieve this the project consumes two NuGets: 25 | 26 | * [Fody](https://www.nuget.org/packages/Fody/) with `PrivateAssets="None"`. This results in producing NuGet package having a dependency on Fody with all `include="All"` in the nuspec. Note that while this project consumes the Fody NuGet, weaving is not performed on this project. This is due to the FodyPackaging NuGet (see below) including `true` in the MSBuild pipeline. 27 | * [FodyPackaging](addin-packaging.md#fodypackaging-nuget-package) with `PrivateAssets="All"`. This results in a NuGet package being produced by this project, but no dependency on FodyPackaging in the resulting NuGet package. 28 | 29 | The produced NuGet package will: 30 | 31 | * Be named with `.Fody` suffix. This project should also contain all appropriate [NuGet metadata properties](https://docs.microsoft.com/en-us/dotnet/core/tools/csproj#nuget-metadata-properties). Many of these properties have defaults in [FodyPackaging](https://github.com/Fody/Fody/blob/master/FodyPackaging/build/FodyPackaging.props), but can be overridden. 32 | * Target, and hence support from a consumer perspective, the same frameworks that this project targets. 33 | * Be created in a directory named `nugets` at the root of the solution. 34 | 35 | 36 | 37 | ```csproj 38 | 39 | 40 | 41 | net452;netstandard2.0;netstandard2.1 42 | true 43 | key.snk 44 | Simon Cropp 45 | Copyright $([System.DateTime]::UtcNow.ToString(yyyy)). 46 | Injects a new type that writes "Hello World". 47 | MIT 48 | 49 | Hello World, ILWeaving, Fody, Cecil, AOP 50 | $(SolutionDir)../nugets 51 | https://github.com/Fody/Home/tree/master/BasicFodyAddin 52 | https://raw.githubusercontent.com/Fody/Home/master/BasicFodyAddin/package_icon.png 53 | 54 | 55 | 56 | 57 | 58 | 59 | ``` 60 | snippet source | anchor 61 | 62 | 63 | 64 | ### Build Order 65 | 66 | The Lib/Reference project must contain a [Project Dependency](https://docs.microsoft.com/en-us/visualstudio/ide/how-to-create-and-remove-project-dependencies?view=vs-2019) on the [Weaver-Project](Weaver-Project) to ensure it is built after the Weaver Project produces its output. 67 | 68 | ![project dependencies](project-dependencies.png) 69 | 70 | If a weaver file cannot be found, the build will fail with one of the following: 71 | 72 | > FodyPackaging: No weaver found at [PATH]. BasicFodyAddin should have a Project Dependency on BasicFodyAddin.Fody. 73 | 74 | 75 | ## Weaver Project 76 | 77 | [BasicFodyAddin.Fody.csproj](/BasicFodyAddin/BasicFodyAddin.Fody/) 78 | 79 | This project contains the weaving code. 80 | 81 | * Has a NuGet dependency on [FodyHelpers](https://www.nuget.org/packages/FodyHelpers/). 82 | * Should not have any runtime dependencies (excluding Mono Cecil); runtime dependencies should be combined using e.g. [ILMerge](https://github.com/dotnet/ILMerge) and the `/Internalize` flag. 83 | * The assembly must contain a public class named 'ModuleWeaver'. The namespace does not matter. 84 | 85 | 86 | 87 | ```csproj 88 | 89 | 90 | 91 | netstandard2.0 92 | 93 | 94 | 95 | 96 | 97 | ``` 98 | snippet source | anchor 99 | 100 | 101 | 102 | ### Target Frameworks 103 | 104 | This project must target `netstandard2.0`. 105 | 106 | 107 | ### Output of the project 108 | 109 | It outputs a file named `BasicFodyAddin.Fody`. The '.Fody' suffix is necessary to be picked up by Fody at compile time. 110 | 111 | 112 | ### ModuleWeaver 113 | 114 | ModuleWeaver.cs is where the target assembly is modified. Fody will pick up this type during its processing. Note that the class must be named as `ModuleWeaver`. 115 | 116 | `ModuleWeaver` must use the base class of `BaseModuleWeaver` which exists in the [FodyHelpers NuGet](https://www.nuget.org/packages/FodyHelpers/). 117 | 118 | * Inherit from `BaseModuleWeaver`. 119 | * The class must be public, non static, and not abstract. 120 | * Have an empty constructor. 121 | 122 | 123 | 124 | ```cs 125 | public class ModuleWeaver : 126 | BaseModuleWeaver 127 | { 128 | 129 | public override void Execute() 130 | { 131 | var ns = GetNamespace(); 132 | var type = new TypeDefinition(ns, "Hello", TypeAttributes.Public, TypeSystem.ObjectReference); 133 | 134 | AddConstructor(type); 135 | 136 | AddHelloWorld(type); 137 | 138 | ModuleDefinition.Types.Add(type); 139 | WriteInfo("Added type 'Hello' with method 'World'."); 140 | } 141 | 142 | public override IEnumerable GetAssembliesForScanning() 143 | { 144 | yield return "netstandard"; 145 | yield return "mscorlib"; 146 | } 147 | 148 | string GetNamespace() 149 | { 150 | var namespaceFromConfig = GetNamespaceFromConfig(); 151 | var namespaceFromAttribute = GetNamespaceFromAttribute(); 152 | if (namespaceFromConfig != null && namespaceFromAttribute != null) 153 | { 154 | throw new WeavingException("Configuring namespace from both Config and Attribute is not supported."); 155 | } 156 | 157 | if (namespaceFromAttribute != null) 158 | { 159 | return namespaceFromAttribute; 160 | } 161 | 162 | return namespaceFromConfig; 163 | } 164 | 165 | string GetNamespaceFromConfig() 166 | { 167 | var attribute = Config?.Attribute("Namespace"); 168 | if (attribute == null) 169 | { 170 | return null; 171 | } 172 | 173 | var value = attribute.Value; 174 | ValidateNamespace(value); 175 | return value; 176 | } 177 | 178 | string GetNamespaceFromAttribute() 179 | { 180 | var attributes = ModuleDefinition.Assembly.CustomAttributes; 181 | var namespaceAttribute = attributes 182 | .SingleOrDefault(x => x.AttributeType.FullName == "NamespaceAttribute"); 183 | if (namespaceAttribute == null) 184 | { 185 | return null; 186 | } 187 | 188 | attributes.Remove(namespaceAttribute); 189 | var value = (string)namespaceAttribute.ConstructorArguments.First().Value; 190 | ValidateNamespace(value); 191 | return value; 192 | } 193 | 194 | static void ValidateNamespace(string value) 195 | { 196 | if (value is null || string.IsNullOrWhiteSpace(value)) 197 | { 198 | throw new WeavingException("Invalid namespace"); 199 | } 200 | } 201 | 202 | void AddConstructor(TypeDefinition newType) 203 | { 204 | var attributes = MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName; 205 | var method = new MethodDefinition(".ctor", attributes, TypeSystem.VoidReference); 206 | var objectConstructor = ModuleDefinition.ImportReference(TypeSystem.ObjectDefinition.GetConstructors().First()); 207 | var processor = method.Body.GetILProcessor(); 208 | processor.Emit(OpCodes.Ldarg_0); 209 | processor.Emit(OpCodes.Call, objectConstructor); 210 | processor.Emit(OpCodes.Ret); 211 | newType.Methods.Add(method); 212 | } 213 | 214 | void AddHelloWorld(TypeDefinition newType) 215 | { 216 | var method = new MethodDefinition("World", MethodAttributes.Public, TypeSystem.StringReference); 217 | var processor = method.Body.GetILProcessor(); 218 | processor.Emit(OpCodes.Ldstr, "Hello World"); 219 | processor.Emit(OpCodes.Ret); 220 | newType.Methods.Add(method); 221 | } 222 | 223 | public override bool ShouldCleanReference => true; 224 | } 225 | ``` 226 | snippet source | anchor 227 | 228 | 229 | 230 | #### BaseModuleWeaver.Execute 231 | 232 | Called to perform the manipulation of the module. The current module can be accessed and manipulated via `BaseModuleWeaver.ModuleDefinition`. 233 | 234 | 235 | 236 | ```cs 237 | public override void Execute() 238 | { 239 | var ns = GetNamespace(); 240 | var type = new TypeDefinition(ns, "Hello", TypeAttributes.Public, TypeSystem.ObjectReference); 241 | 242 | AddConstructor(type); 243 | 244 | AddHelloWorld(type); 245 | 246 | ModuleDefinition.Types.Add(type); 247 | WriteInfo("Added type 'Hello' with method 'World'."); 248 | } 249 | ``` 250 | snippet source | anchor 251 | 252 | 253 | 254 | #### Resultant injected code 255 | 256 | In this case a new type is being injected into the target assembly that looks like this. 257 | 258 | ```csharp 259 | public class Hello 260 | { 261 | public string World() 262 | { 263 | return "Hello World"; 264 | } 265 | } 266 | ``` 267 | 268 | 269 | #### BaseModuleWeaver.GetAssembliesForScanning 270 | 271 | Called by Fody when it is building up a type cache for lookups. This method should return all possible assemblies that the weaver may require while resolving types. In this case BasicFodyAddin requires `System.Object`, so `GetAssembliesForScanning` returns `netstandard` and `mscorlib`. It is safe to return assembly names that are not used by the current target assembly as these will be ignored. 272 | 273 | To use this type cache, a `ModuleWeaver` can call `BaseModuleWeaver.FindType` within `Execute` method. 274 | 275 | 276 | 277 | ```cs 278 | public override IEnumerable GetAssembliesForScanning() 279 | { 280 | yield return "netstandard"; 281 | yield return "mscorlib"; 282 | } 283 | ``` 284 | snippet source | anchor 285 | 286 | 287 | 288 | #### BaseModuleWeaver.ShouldCleanReference 289 | 290 | When `BasicFodyAddin.dll` is referenced by a consuming project, it is only for the purposes configuring the weaving via attributes. As such, it is not required at runtime. With this in mind `BaseModuleWeaver` has an opt in feature to remove the reference, meaning the target weaved application does not need `BasicFodyAddin.dll` at runtime. This feature can be opted in to via the following code in `ModuleWeaver`: 291 | 292 | 293 | 294 | ```cs 295 | public override bool ShouldCleanReference => true; 296 | ``` 297 | snippet source | anchor 298 | 299 | 300 | 301 | #### Logging 302 | 303 | Many helpers exist for writing log entries to MSBuild: 304 | 305 | 306 | 307 | ```cs 308 | using System.Collections.Generic; 309 | using System.Linq; 310 | using Fody; 311 | 312 | public class MyLoggingWeaver : 313 | BaseModuleWeaver 314 | { 315 | public override void Execute() 316 | { 317 | // Write a log entry with a specific MessageImportance 318 | WriteMessage("Message", MessageImportance.High); 319 | 320 | // Write a log entry with the MessageImportance.Low level 321 | WriteDebug("Message"); 322 | 323 | // Write a log entry with the MessageImportance.Normal level 324 | WriteInfo("Message"); 325 | 326 | // Write a warning 327 | WriteWarning("Message"); 328 | 329 | // Write an error 330 | WriteError("Message"); 331 | 332 | var type = ModuleDefinition.GetType("MyType"); 333 | var method = type.Methods.First(); 334 | 335 | // Write an error using the first SequencePoint 336 | // of a method for the line information 337 | WriteWarning("Message", method); 338 | 339 | // Write an error using the first SequencePoint 340 | // of a method for the line information 341 | WriteError("Message", method); 342 | 343 | var sequencePoint = method.DebugInformation.SequencePoints.First(); 344 | 345 | // Write an warning using a SequencePoint 346 | // for the line information 347 | WriteWarning("Message", sequencePoint); 348 | 349 | // Write an error using a SequencePoint 350 | // for the line information 351 | WriteError("Message", sequencePoint); 352 | } 353 | 354 | public override IEnumerable GetAssembliesForScanning() => Enumerable.Empty(); 355 | } 356 | ``` 357 | snippet source | anchor 358 | 359 | 360 | 361 | #### Other BaseModuleWeaver Members 362 | 363 | `BaseModuleWeaver` has other members for extensibility: 364 | https://github.com/Fody/Fody/blob/master/FodyHelpers/BaseModuleWeaver.cs 365 | 366 | 367 | ### Throwing exceptions 368 | 369 | When writing an addin there are a points to note when throwing an Exception. 370 | 371 | * Exceptions thrown from an addin will be caught and interpreted as a build error. So this will stop the build. 372 | * The exception information will be logged to the MSBuild `BuildEngine.LogErrorEvent` method. 373 | * If the exception type is `WeavingException` then it will be interpreted as an "error". So the addin is explicitly throwing an exception with the intent of stopping processing and logging a message to the build log. In this case the message logged will be the contents of `WeavingException.Message` property. If the `WeavingException` has a property `SequencePoint` then that information will be passed to the build engine so a user can navigate to the error. 374 | * If the exception type is *not* a `WeavingException` then it will be interpreted as an "unhandled exception". So something has gone seriously wrong with the addin. It most likely has a bug. In this case message logged be much bore verbose and will contain the full contents of the Exception. The code for getting the message can be found here in [ExceptionExtensions](https://github.com/Fody/Fody/blob/master/FodyCommon/ExceptionExtensions.cs). 375 | 376 | 377 | ## Passing config via to FodyWeavers.xml 378 | 379 | This file exists at a project level in the users target project and is used to pass configuration to the 'ModuleWeaver'. 380 | 381 | So if the FodyWeavers.xml file contains the following: 382 | 383 | ```xml 384 | 385 | 386 | 387 | ``` 388 | 389 | The property of the `ModuleWeaver.Config` will be an [XElement](https://docs.microsoft.com/en-us/dotnet/api/system.xml.linq.xelement) containing: 390 | 391 | ```xml 392 | 393 | ``` 394 | 395 | 396 | ### Supporting intellisense for FodyWeavers.xml 397 | 398 | Fody will create or update a schema file (FodyWeavers.xsd) for every FodyWeavers.xml during compilation, adding all detected weavers. Every weaver now can provide a schema fragment describing it's individual properties and content that can be set. This file must be part of the weaver project and named `.xcf`. It contains the element describing the type of the configuration node. The file must be published side by side with the weaver file; however [FodyPackaging](fodypackaging.md) will configure this correctly based on the convention `WeaverName.Fody.xcf`. 399 | 400 | Sample content of the `BasicFodyAddin.Fody.xcf`: 401 | 402 | 403 | 404 | ```xcf 405 | 406 | 407 | 409 | 410 | Namespace to use for the injected type 411 | 412 | 413 | 414 | ``` 415 | snippet source | anchor 416 | 417 | 418 | Fody will then combine all `.xcf` fragments with the weavers information to the final `.xsd`: 419 | 420 | 421 | 422 | ```xsd 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | Namespace to use for the injected type 434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed. 442 | 443 | 444 | 445 | 446 | A comma-separated list of error codes that can be safely ignored in assembly verification. 447 | 448 | 449 | 450 | 451 | 'false' to turn off automatic generation of the XML Schema file. 452 | 453 | 454 | 455 | 456 | 457 | ``` 458 | snippet source | anchor 459 | 460 | 461 | 462 | ## AssemblyToProcess Project 463 | 464 | [AssemblyToProcess.csproj](/BasicFodyAddin/AssemblyToProcess/) 465 | 466 | A target assembly to process and then validate with unit tests. 467 | 468 | 469 | ## Tests Project 470 | 471 | [Tests.csproj](/BasicFodyAddin/Tests/) 472 | 473 | Contains all tests for the weaver. 474 | 475 | The project has a NuGet dependency on [FodyHelpers](https://www.nuget.org/packages/FodyHelpers/). 476 | 477 | It has a reference to the `AssemblyToProcess` project, so that `AssemblyToProcess.dll` is copied to the bin directory of the test project. 478 | 479 | FodyHelpers contains a utility [WeaverTestHelper](https://github.com/Fody/Fody/blob/master/FodyHelpers/Testing/WeaverTestHelper.cs) for executing test runs on a target assembly using a ModuleWeaver. 480 | 481 | A test can then be run as follows: 482 | 483 | 484 | 485 | ```cs 486 | public class WeaverTests 487 | { 488 | static TestResult testResult; 489 | 490 | static WeaverTests() 491 | { 492 | var weavingTask = new ModuleWeaver(); 493 | testResult = weavingTask.ExecuteTestRun("AssemblyToProcess.dll"); 494 | } 495 | 496 | [Fact] 497 | public void ValidateHelloWorldIsInjected() 498 | { 499 | var type = testResult.Assembly.GetType("TheNamespace.Hello"); 500 | var instance = (dynamic)Activator.CreateInstance(type); 501 | 502 | Assert.Equal("Hello World", instance.World()); 503 | } 504 | } 505 | ``` 506 | snippet source | anchor 507 | 508 | 509 | By default `ExecuteTestRun` will perform a [PeVerify](https://docs.microsoft.com/en-us/dotnet/framework/tools/peverify-exe-peverify-tool) on the resultant assembly. 510 | 511 | 512 | 513 | ```csproj 514 | 515 | 516 | 517 | net472;netcoreapp2.2 518 | true 519 | 520 | 521 | 522 | 523 | 524 | 525 | 526 | 527 | 528 | 529 | 530 | 531 | ``` 532 | snippet source | anchor 533 | 534 | 535 | 536 | ## Build Server 537 | 538 | 539 | ### AppVeyor 540 | 541 | To configure an adding to build using [AppVeyor](https://www.appveyor.com/) use the following `appveyor.yml`: 542 | 543 | 544 | 545 | ```yml 546 | image: Visual Studio 2022 547 | skip_commits: 548 | message: /docs|Merge pull request.*/ 549 | build_script: 550 | - ps: >- 551 | dotnet build BasicFodyAddin --configuration Release 552 | 553 | dotnet test BasicFodyAddin --configuration Release --no-build --no-restore 554 | test: off 555 | artifacts: 556 | - path: nugets\*.nupkg 557 | ``` 558 | snippet source | anchor 559 | 560 | 561 | 562 | ## Usage 563 | 564 | 565 | ### NuGet installation 566 | 567 | Install the [BasicFodyAddin.Fody NuGet package](https://www.nuget.org/packages/BasicFodyAddin.Fody/) and update the [Fody NuGet package](https://www.nuget.org/packages/Fody/): 568 | 569 | ```powershell 570 | PM> Install-Package Fody 571 | PM> Install-Package BasicFodyAddin.Fody 572 | ``` 573 | 574 | The `Install-Package Fody` is required since NuGet always defaults to the oldest, and most buggy, version of any dependency. 575 | 576 | 577 | ### Add to FodyWeavers.xml 578 | 579 | ```xml 580 | 581 | 582 | 583 | ``` 584 | 585 | 586 | ## Deployment 587 | 588 | Addins are deployed through [NuGet](https://www.nuget.org/) packages. The package must: 589 | 590 | * Contain two weaver assemblies, one in each of the folders `netclassicweaver` and `netstandardweaver`, to support both .Net Classic and .Net Core. 591 | * Contain a runtime library, compiled for every supported framework, under the `lib` folder. 592 | * Contain an MsBuild .props file in the `build` folder that registers the weaver at compile time. The name of the file must be the package id with the `.props` extension. See [Addin Discover](addin-discovery.md) for details. 593 | * Have an id with the same name of the weaver assembly should be the same and be suffixed with ".Fody". So in this case the [BasicFodyAddin.Fody NuGet](https://www.nuget.org/packages/BasicFodyAddin.Fody/) contains the weaver assembly `BasicFodyAddin.Fody.dll` and the reference assembly `BasicFodyAddin.dll`. 594 | * Have a single dependency on **only** the [Fody NuGet package](https://www.nuget.org/packages/Fody/). **Do not add any other NuGet dependencies as Fody does not support loading these files at compile time.** 595 | 596 | Note that the addins used via [in-solution-weaving](in-solution-weaving.md) are handled differently. 597 | --------------------------------------------------------------------------------