├── Fody.Tests ├── Solution │ ├── Tools │ │ └── TextFile1.txt │ ├── SearchPath1 │ │ └── TextFile1.txt │ └── SearchPath2 │ │ └── TextFile1.txt ├── NugetPackagePathFinder │ ├── FakeSolutionNoNugetConfig │ │ └── placeholder.txt │ ├── FakeSolutionWithNugetConfig │ │ └── nuget.config │ └── FakeSolutionWithNesetdNugetConfig │ │ └── .nuget │ │ └── nuget.config ├── WeaversProjectFileFinder │ └── WithWeaver │ │ └── Weavers │ │ └── bin │ │ └── Debug │ │ └── Weavers.dll ├── NugetConfigWithRepoNodeEmpty.txt ├── BadAssembly.dll ├── NugetConfigWithKeyNodeEmpty.txt ├── NugetConfigWithRepoNode.txt ├── NugetConfigWithKeyNode.txt ├── ProjectWeaversReaderTests │ ├── FodyWeavers2.xml │ ├── FodyWeavers3.xml │ ├── FodyWeavers1.xml │ └── ProjectWeaversReaderTests.cs ├── ProjectPathFinderTests.cs ├── packages.config ├── DomainAssemblyResolverTests.cs ├── AssemblyPathFinderTests.cs ├── AssemblyVersionReaderTests.cs ├── DynamicTests.cs ├── ShouldStartSinceFileChangedTests.cs ├── WeaverAssemblyPathFinderTests.cs ├── SearchDirectories │ ├── AddToolsAssemblyLocationToAddinSearchTests.cs │ ├── AddToolsSolutionDirectoryToAddinSearchTests.cs │ ├── AddNugetDirectoryToAddinSearchTests.cs │ └── AddinDirectoriesTests.cs ├── FileChangedCheckerTests.cs ├── ContainsTypeCheckerTests.cs ├── ProjectWeaversFinderTests.cs ├── BuildLoggerTests.cs ├── InstanceLinker │ ├── NoWeaversConfiguredInstanceLinkerTests.cs │ └── WeaversConfiguredInstanceLinkerTests.cs ├── AddinFilesEnumeratorTests.cs ├── SolutionPathValidatorTests.cs ├── WeaverProjectFileFinderTests.cs ├── WeaversHistoryTests.cs ├── XmlExtensionsTests.cs ├── WeaversXmlHistoryTests.cs └── NugetConfigReaderTest.cs ├── FodyVsPackage.Tests ├── Tools │ └── Fody │ │ └── PlaceHolder.txt ├── FooTests.cs ├── packages.config ├── CurrentVersionTests.cs ├── FileReader.cs ├── TypeExtensions.cs ├── ContentsFinderTests.cs ├── FodyDirectoryFinderTests.cs ├── VersionCheckerTests.cs ├── PathExTests.cs ├── ExceptionWindowTests.cs ├── ExceptionExtensionsTests.cs ├── ProjectRemoverTests.cs ├── ProjectInjectorTests.cs └── TestProjects │ ├── ProjectWithNoWeaving.csproj │ └── ProjectWithWeaving.csproj ├── Key.snk ├── .nuget └── packages.config ├── Tools ├── Fody │ ├── Fody.dll │ ├── Fody.pdb │ ├── FodyCommon.dll │ ├── FodyCommon.pdb │ ├── Mono.Cecil.dll │ ├── FodyIsolated.dll │ ├── FodyIsolated.pdb │ ├── Mono.Cecil.Mdb.dll │ ├── Mono.Cecil.Pdb.dll │ ├── Mono.Cecil.Rocks.dll │ └── Fody.targets ├── vs2010.sdk │ ├── vsct.exe │ ├── VSCTLibrary.dll │ ├── CreatePkgDef.exe │ ├── VSCTCompress.dll │ ├── Microsoft.VsSDK.Build.Tasks.dll │ ├── Microsoft.VisualStudio.OLE.Interop.dll │ ├── Microsoft.VisualStudio.Shell.10.0.dll │ ├── Microsoft.VisualStudio.Shell.Interop.10.0.dll │ ├── Microsoft.VisualStudio.Shell.Interop.8.0.dll │ ├── Microsoft.VisualStudio.Shell.Interop.9.0.dll │ ├── Microsoft.VisualStudio.Shell.Immutable.10.0.dll │ ├── CreatePkgDef.exe.config │ ├── ProjectItemsSchema.xml │ └── Microsoft.VsSDK.Cpp.targets ├── Pepita │ ├── PepitaGet.dll │ ├── PepitaGet.pdb │ ├── PepitaPackage.dll │ ├── PepitaPackage.pdb │ └── PepitaGet.targets └── SimpleMsBuildTasks.dll ├── FodyVSPackage ├── ILogger.cs ├── ContentFiles │ └── FodyWeavers.xml ├── Resources │ ├── Package.ico │ └── Images_32bit.bmp ├── ConfigFile.cs ├── Logger.cs ├── ExceptionHandling │ ├── ExceptionWindowModel.cs │ ├── ExceptionDialog.cs │ ├── ExceptionWindow.xaml.cs │ ├── ExceptionExtensions.cs │ └── ExceptionWindow.xaml ├── FodyWeavers.xml ├── CurrentVersion.cs ├── packages.config ├── VersionChecker.cs ├── Wpf │ ├── HyperlinkEx.cs │ ├── InverseBooleanConverter.cs │ └── EnumBooleanConverter.cs ├── ContentsFinder.cs ├── MsBuildXmlExtensions.cs ├── AssemblyVersionReader.cs ├── UnsaveProjectChecker.cs ├── MSBuildKiller.cs ├── PathEx.cs ├── ContainsFodyChecker.cs ├── FodyDirectoryFinder.cs ├── CurrentProjectFinder.cs ├── ProjectKind.cs ├── MessageDisplayer.cs ├── License.txt ├── ProjectRemover.cs ├── source.extension.vsixmanifest ├── DisableMenuConfigure.cs ├── AllProjectFinder.cs ├── ProcessExtensions.cs ├── TaskFileProcessor.cs ├── Styles.xaml ├── MenuConfigure.cs ├── ProjectInjector.cs ├── FodyVSPackagePackage.cs ├── FodyVSPackage.vsct └── SolutionEvents.cs ├── Images └── Link.txt ├── Lib └── Cecil │ ├── Mono.Cecil.dll │ ├── Mono.Cecil.pdb │ ├── Mono.Cecil.Mdb.dll │ ├── Mono.Cecil.Mdb.pdb │ ├── Mono.Cecil.Pdb.dll │ ├── Mono.Cecil.Pdb.pdb │ ├── Mono.Cecil.Rocks.dll │ └── Mono.Cecil.Rocks.pdb ├── SampleTask.Fody ├── packages.config ├── FodyWeavers.xml ├── ModuleWeaver.cs └── SampleTask.Fody.csproj ├── FodyCommon ├── FodyWeavers.xml ├── IContainsTypeChecker.cs ├── packages.config ├── WeaverEntry.cs ├── WeavingException.cs ├── IInnerWeaver.cs ├── ILogger.cs ├── ExceptionExtensions.cs └── FodyCommon.csproj ├── Integration ├── WithNugetWeavers │ ├── FodyWeavers.xml │ ├── packages.config │ ├── Class1.cs │ └── WithNugetWeavers.csproj ├── Tests │ ├── packages.config │ ├── WithNugetWeaversTest.cs │ ├── WithOnlyInSolutionWeaverTest.cs │ ├── WithNugetAndInSolutionWeaversTest.cs │ └── Tests.csproj ├── Weavers │ ├── packages.config │ ├── ModuleWeaver.cs │ ├── NamedWeaver.cs │ ├── Weavers.ncrunchproject │ └── Weavers.csproj ├── .nuget │ └── packages.config ├── packages │ └── Virtuosity.Fody.1.13.0.0 │ │ └── Virtuosity.Fody.dll ├── WithNugetAndInSolutionWeavers │ ├── FodyWeavers.xml │ ├── packages.config │ ├── Class1.cs │ ├── WithNugetAndInSolutionWeavers.ncrunchproject │ └── WithNugetAndInSolutionWeavers.csproj └── WithOnlyInSolutionWeaver │ ├── Class1.cs │ ├── WithOnlyInSolutionWeaver.ncrunchproject │ └── WithOnlyInSolutionWeaver.csproj ├── FodyIsolated ├── FodyWeavers.xml ├── packages.config ├── ExceptionExtensions.cs ├── InstanceConstructor.cs ├── IsolatedContainsTypeChecker.cs ├── TypeFinder.cs ├── ModuleWeaverRunner.cs ├── AssemblyReferenceFinder.cs ├── SymbolsFinder.cs ├── ModuleReader.cs ├── ObjectTypeName.cs ├── ModuleWriter.cs ├── AssemblyLoader.cs ├── StrongNameKeyFinder.cs └── InnerWeaver.cs ├── FodyCommon.Tests ├── packages.config ├── ToFriendlyStringTests.cs └── FodyCommon.Tests.csproj ├── Fody ├── FodyWeavers.xml ├── FileChangedChecker.cs ├── packages.config ├── ProjectPathFinder.cs ├── WeaverAssemblyPathFinder.cs ├── DomainAssemblyResolver.cs ├── AssemblyPathValidator.cs ├── AssemblyVersionReader.cs ├── WeaverProjectContainsWeaverChecker.cs ├── SolutionPathValidator.cs ├── AddinFinder │ ├── AddToolsAssemblyLocationToAddinSearch.cs │ ├── AddinFilesEnumerator.cs │ └── AddinSearchDirectories.cs ├── AssemblyLocation.cs ├── XmlExtensions.cs ├── WeaversHistory.cs ├── ContainsTypeChecker.cs ├── InstanceLinker │ ├── NoWeaversConfiguredInstanceLinker.cs │ └── WeaversConfiguredInstanceLinker.cs ├── WeaversXmlHistory.cs ├── WeavingTask.cs ├── WeaverProjectFileFinder.cs ├── ProjectWeaversFinder.cs ├── ProjectWeaversReader.cs └── BuildLogger.cs ├── CommonAssemblyInfo.cs ├── FodyIsolated.Tests ├── packages.config ├── ObjectTypeNameTests.cs ├── TypeFinderTest.cs ├── IsolatedContainsTypeCheckerTests.cs ├── InstanceConstructorTests.cs ├── ModuleWeaverRunnerTests.cs └── WeaverInitialiserTests.cs ├── .gitattributes ├── packages └── repositories.config ├── ChocolateyNuGet ├── Fody.nuspec ├── chocolateyInstall.ps1 └── ChocolateyNuget.csproj ├── License.txt ├── .gitignore ├── NugetConfigReader.cs └── Fody.targets /Fody.Tests/Solution/Tools/TextFile1.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Fody.Tests/Solution/SearchPath1/TextFile1.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Fody.Tests/Solution/SearchPath2/TextFile1.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /FodyVsPackage.Tests/Tools/Fody/PlaceHolder.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Key.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shanselman/Fody/master/Key.snk -------------------------------------------------------------------------------- /Fody.Tests/NugetPackagePathFinder/FakeSolutionNoNugetConfig/placeholder.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Fody.Tests/WeaversProjectFileFinder/WithWeaver/Weavers/bin/Debug/Weavers.dll: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Fody.Tests/NugetConfigWithRepoNodeEmpty.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /.nuget/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /Tools/Fody/Fody.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shanselman/Fody/master/Tools/Fody/Fody.dll -------------------------------------------------------------------------------- /Tools/Fody/Fody.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shanselman/Fody/master/Tools/Fody/Fody.pdb -------------------------------------------------------------------------------- /FodyVSPackage/ILogger.cs: -------------------------------------------------------------------------------- 1 | public interface ILogger 2 | { 3 | void LogInfo(string format); 4 | } -------------------------------------------------------------------------------- /Images/Link.txt: -------------------------------------------------------------------------------- 1 | http://www.clker.com/disclaimer.html 2 | http://www.clker.com/clipart-23981.html -------------------------------------------------------------------------------- /Lib/Cecil/Mono.Cecil.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shanselman/Fody/master/Lib/Cecil/Mono.Cecil.dll -------------------------------------------------------------------------------- /Lib/Cecil/Mono.Cecil.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shanselman/Fody/master/Lib/Cecil/Mono.Cecil.pdb -------------------------------------------------------------------------------- /SampleTask.Fody/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /Tools/Fody/FodyCommon.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shanselman/Fody/master/Tools/Fody/FodyCommon.dll -------------------------------------------------------------------------------- /Tools/Fody/FodyCommon.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shanselman/Fody/master/Tools/Fody/FodyCommon.pdb -------------------------------------------------------------------------------- /Tools/Fody/Mono.Cecil.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shanselman/Fody/master/Tools/Fody/Mono.Cecil.dll -------------------------------------------------------------------------------- /Tools/vs2010.sdk/vsct.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shanselman/Fody/master/Tools/vs2010.sdk/vsct.exe -------------------------------------------------------------------------------- /Fody.Tests/BadAssembly.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shanselman/Fody/master/Fody.Tests/BadAssembly.dll -------------------------------------------------------------------------------- /Tools/Fody/FodyIsolated.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shanselman/Fody/master/Tools/Fody/FodyIsolated.dll -------------------------------------------------------------------------------- /Tools/Fody/FodyIsolated.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shanselman/Fody/master/Tools/Fody/FodyIsolated.pdb -------------------------------------------------------------------------------- /Tools/Pepita/PepitaGet.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shanselman/Fody/master/Tools/Pepita/PepitaGet.dll -------------------------------------------------------------------------------- /Tools/Pepita/PepitaGet.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shanselman/Fody/master/Tools/Pepita/PepitaGet.pdb -------------------------------------------------------------------------------- /FodyCommon/FodyWeavers.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Lib/Cecil/Mono.Cecil.Mdb.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shanselman/Fody/master/Lib/Cecil/Mono.Cecil.Mdb.dll -------------------------------------------------------------------------------- /Lib/Cecil/Mono.Cecil.Mdb.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shanselman/Fody/master/Lib/Cecil/Mono.Cecil.Mdb.pdb -------------------------------------------------------------------------------- /Lib/Cecil/Mono.Cecil.Pdb.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shanselman/Fody/master/Lib/Cecil/Mono.Cecil.Pdb.dll -------------------------------------------------------------------------------- /Lib/Cecil/Mono.Cecil.Pdb.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shanselman/Fody/master/Lib/Cecil/Mono.Cecil.Pdb.pdb -------------------------------------------------------------------------------- /Lib/Cecil/Mono.Cecil.Rocks.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shanselman/Fody/master/Lib/Cecil/Mono.Cecil.Rocks.dll -------------------------------------------------------------------------------- /Lib/Cecil/Mono.Cecil.Rocks.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shanselman/Fody/master/Lib/Cecil/Mono.Cecil.Rocks.pdb -------------------------------------------------------------------------------- /Tools/Fody/Mono.Cecil.Mdb.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shanselman/Fody/master/Tools/Fody/Mono.Cecil.Mdb.dll -------------------------------------------------------------------------------- /Tools/Fody/Mono.Cecil.Pdb.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shanselman/Fody/master/Tools/Fody/Mono.Cecil.Pdb.dll -------------------------------------------------------------------------------- /Tools/Pepita/PepitaPackage.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shanselman/Fody/master/Tools/Pepita/PepitaPackage.dll -------------------------------------------------------------------------------- /Tools/Pepita/PepitaPackage.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shanselman/Fody/master/Tools/Pepita/PepitaPackage.pdb -------------------------------------------------------------------------------- /Tools/SimpleMsBuildTasks.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shanselman/Fody/master/Tools/SimpleMsBuildTasks.dll -------------------------------------------------------------------------------- /Fody.Tests/NugetConfigWithKeyNodeEmpty.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /FodyVSPackage/ContentFiles/FodyWeavers.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Tools/Fody/Mono.Cecil.Rocks.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shanselman/Fody/master/Tools/Fody/Mono.Cecil.Rocks.dll -------------------------------------------------------------------------------- /Tools/vs2010.sdk/VSCTLibrary.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shanselman/Fody/master/Tools/vs2010.sdk/VSCTLibrary.dll -------------------------------------------------------------------------------- /FodyVSPackage/Resources/Package.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shanselman/Fody/master/FodyVSPackage/Resources/Package.ico -------------------------------------------------------------------------------- /Tools/vs2010.sdk/CreatePkgDef.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shanselman/Fody/master/Tools/vs2010.sdk/CreatePkgDef.exe -------------------------------------------------------------------------------- /Tools/vs2010.sdk/VSCTCompress.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shanselman/Fody/master/Tools/vs2010.sdk/VSCTCompress.dll -------------------------------------------------------------------------------- /FodyVSPackage/ConfigFile.cs: -------------------------------------------------------------------------------- 1 | static class ConfigFile 2 | { 3 | public const string FodyWeaversXml = "FodyWeavers.xml"; 4 | } -------------------------------------------------------------------------------- /Fody.Tests/NugetConfigWithRepoNode.txt: -------------------------------------------------------------------------------- 1 | 2 | repositoryPathValue 3 | -------------------------------------------------------------------------------- /FodyVSPackage/Resources/Images_32bit.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shanselman/Fody/master/FodyVSPackage/Resources/Images_32bit.bmp -------------------------------------------------------------------------------- /FodyVSPackage/Logger.cs: -------------------------------------------------------------------------------- 1 | public class Logger 2 | { 3 | public static void LogInfo(string format) 4 | { 5 | 6 | } 7 | } -------------------------------------------------------------------------------- /Integration/WithNugetWeavers/FodyWeavers.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /FodyCommon/IContainsTypeChecker.cs: -------------------------------------------------------------------------------- 1 | public interface IContainsTypeChecker 2 | { 3 | bool Check(string assemblyPath, string typeName); 4 | } -------------------------------------------------------------------------------- /SampleTask.Fody/FodyWeavers.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /FodyVSPackage/ExceptionHandling/ExceptionWindowModel.cs: -------------------------------------------------------------------------------- 1 | public class ExceptionWindowModel 2 | { 3 | public string ExceptionText { get; set; } 4 | } -------------------------------------------------------------------------------- /Integration/Tests/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Tools/vs2010.sdk/Microsoft.VsSDK.Build.Tasks.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shanselman/Fody/master/Tools/vs2010.sdk/Microsoft.VsSDK.Build.Tasks.dll -------------------------------------------------------------------------------- /FodyIsolated/FodyWeavers.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /FodyVSPackage/FodyWeavers.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Integration/Weavers/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Integration/.nuget/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Tools/vs2010.sdk/Microsoft.VisualStudio.OLE.Interop.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shanselman/Fody/master/Tools/vs2010.sdk/Microsoft.VisualStudio.OLE.Interop.dll -------------------------------------------------------------------------------- /Tools/vs2010.sdk/Microsoft.VisualStudio.Shell.10.0.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shanselman/Fody/master/Tools/vs2010.sdk/Microsoft.VisualStudio.Shell.10.0.dll -------------------------------------------------------------------------------- /Fody.Tests/NugetPackagePathFinder/FakeSolutionWithNugetConfig/nuget.config: -------------------------------------------------------------------------------- 1 | 2 | FromNugetConfig 3 | -------------------------------------------------------------------------------- /FodyCommon.Tests/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /FodyCommon/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Fody.Tests/NugetConfigWithKeyNode.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Fody.Tests/NugetPackagePathFinder/FakeSolutionWithNesetdNugetConfig/.nuget/nuget.config: -------------------------------------------------------------------------------- 1 | 2 | FromNugetConfig 3 | -------------------------------------------------------------------------------- /Fody/FodyWeavers.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Tools/vs2010.sdk/Microsoft.VisualStudio.Shell.Interop.10.0.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shanselman/Fody/master/Tools/vs2010.sdk/Microsoft.VisualStudio.Shell.Interop.10.0.dll -------------------------------------------------------------------------------- /Tools/vs2010.sdk/Microsoft.VisualStudio.Shell.Interop.8.0.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shanselman/Fody/master/Tools/vs2010.sdk/Microsoft.VisualStudio.Shell.Interop.8.0.dll -------------------------------------------------------------------------------- /Tools/vs2010.sdk/Microsoft.VisualStudio.Shell.Interop.9.0.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shanselman/Fody/master/Tools/vs2010.sdk/Microsoft.VisualStudio.Shell.Interop.9.0.dll -------------------------------------------------------------------------------- /Fody.Tests/ProjectWeaversReaderTests/FodyWeavers2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /Fody.Tests/ProjectWeaversReaderTests/FodyWeavers3.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Integration/packages/Virtuosity.Fody.1.13.0.0/Virtuosity.Fody.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shanselman/Fody/master/Integration/packages/Virtuosity.Fody.1.13.0.0/Virtuosity.Fody.dll -------------------------------------------------------------------------------- /Tools/vs2010.sdk/Microsoft.VisualStudio.Shell.Immutable.10.0.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shanselman/Fody/master/Tools/vs2010.sdk/Microsoft.VisualStudio.Shell.Immutable.10.0.dll -------------------------------------------------------------------------------- /Integration/WithNugetAndInSolutionWeavers/FodyWeavers.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /FodyVsPackage.Tests/FooTests.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | 3 | [TestFixture] 4 | public class FooTests 5 | { 6 | 7 | [Test] 8 | public void Bar() 9 | { 10 | } 11 | } -------------------------------------------------------------------------------- /Integration/WithNugetWeavers/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Integration/WithNugetAndInSolutionWeavers/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Fody.Tests/ProjectPathFinderTests.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | 3 | [TestFixture] 4 | public class ProjectPathFinderTests 5 | { 6 | 7 | [Test] 8 | public void Execute() 9 | { 10 | } 11 | } -------------------------------------------------------------------------------- /CommonAssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | 3 | [assembly: AssemblyTitle("Fody")] 4 | [assembly: AssemblyProduct("Fody")] 5 | [assembly: AssemblyVersion("1.8.14.0")] 6 | [assembly: AssemblyFileVersion("1.8.14.0")] 7 | -------------------------------------------------------------------------------- /Fody.Tests/ProjectWeaversReaderTests/FodyWeavers1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Integration/WithNugetWeavers/Class1.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace WithNugetWeavers 3 | { 4 | public class Class1 5 | { 6 | public void Method() 7 | { 8 | 9 | } 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /Fody.Tests/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /FodyVSPackage/CurrentVersion.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public static class CurrentVersion 4 | { 5 | public static Version Version 6 | { 7 | get { return typeof(ContentsFinder).Assembly.GetName().Version; } 8 | } 9 | } -------------------------------------------------------------------------------- /FodyIsolated.Tests/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /FodyCommon/WeaverEntry.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | [Serializable] 4 | public class WeaverEntry 5 | { 6 | public string Element; 7 | public string AssemblyName; 8 | public string AssemblyPath; 9 | public string TypeName; 10 | } -------------------------------------------------------------------------------- /FodyVsPackage.Tests/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /Integration/WithNugetAndInSolutionWeavers/Class1.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace WithNugetAndInSolutionWeavers 3 | { 4 | public class Class1 5 | { 6 | public void Method() 7 | { 8 | 9 | } 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /Integration/WithOnlyInSolutionWeaver/Class1.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace WithOnlyInSolutionWeaver 3 | { 4 | public class Class1 5 | { 6 | public void Method() 7 | { 8 | 9 | } 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /FodyCommon/WeavingException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public class WeavingException : Exception 4 | { 5 | public WeavingException(string message) 6 | : base(message) 7 | { 8 | 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /FodyVsPackage.Tests/CurrentVersionTests.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | 3 | [TestFixture] 4 | public class CurrentVersionTests 5 | { 6 | [Test] 7 | public void Simple() 8 | { 9 | Assert.IsNotNull(CurrentVersion.Version); 10 | } 11 | } -------------------------------------------------------------------------------- /FodyVsPackage.Tests/FileReader.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | 3 | public static class FileReader 4 | { 5 | 6 | public static string Read(string path) 7 | { 8 | return File.ReadAllText(Path.GetFullPath(path)) 9 | .Replace("\r\n", "\n"); 10 | } 11 | } -------------------------------------------------------------------------------- /FodyIsolated.Tests/ObjectTypeNameTests.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | 3 | [TestFixture] 4 | public class ObjectTypeNameTests 5 | { 6 | 7 | [Test] 8 | public void Simple() 9 | { 10 | Assert.AreEqual("System.String, mscorlib", "".GetTypeName()); 11 | } 12 | } -------------------------------------------------------------------------------- /FodyIsolated/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /FodyVSPackage/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Integration/Tests/WithNugetWeaversTest.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using WithNugetWeavers; 3 | 4 | [TestFixture] 5 | public class WithNugetWeaversTest 6 | { 7 | [Test] 8 | public void EnsureTypeChangedByNugetWeaver() 9 | { 10 | Assert.IsTrue(typeof(Class1).GetMethod("Method").IsVirtual); 11 | } 12 | } -------------------------------------------------------------------------------- /Fody.Tests/DomainAssemblyResolverTests.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | 3 | [TestFixture] 4 | public class DomainAssemblyResolverTests 5 | { 6 | [Test] 7 | public void GetAssembly() 8 | { 9 | Assert.IsNotNull( DomainAssemblyResolver.GetAssembly(GetType().Assembly.GetName().FullName)); 10 | } 11 | } 12 | 13 | -------------------------------------------------------------------------------- /FodyVSPackage/VersionChecker.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | 3 | public static class VersionChecker 4 | { 5 | public static bool IsVersionNewer(string targetFile) 6 | { 7 | var existingVersion = AssemblyName.GetAssemblyName(targetFile).Version; 8 | return existingVersion < CurrentVersion.Version; 9 | } 10 | } -------------------------------------------------------------------------------- /FodyVSPackage/Wpf/HyperlinkEx.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics; 2 | using System.Windows.Documents; 3 | 4 | namespace Wpf 5 | { 6 | public class HyperlinkEx : Hyperlink 7 | { 8 | public HyperlinkEx() 9 | { 10 | RequestNavigate += (sender, e) => Process.Start(e.Uri.ToString()); 11 | } 12 | } 13 | } -------------------------------------------------------------------------------- /FodyVsPackage.Tests/TypeExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public static class TypeExtensions 4 | { 5 | public static object GetDefault(this Type type) 6 | { 7 | if (type.IsValueType) 8 | { 9 | return Activator.CreateInstance(type); 10 | } 11 | return null; 12 | } 13 | 14 | 15 | } -------------------------------------------------------------------------------- /FodyVsPackage.Tests/ContentsFinderTests.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics; 2 | using NUnit.Framework; 3 | 4 | [TestFixture] 5 | public class ContentsFinderTests 6 | { 7 | [Test] 8 | public void Simple() 9 | { 10 | var contentsFinder = new ContentsFinder(); 11 | Debug.WriteLine(contentsFinder.ContentFilesPath); 12 | } 13 | } -------------------------------------------------------------------------------- /Fody.Tests/AssemblyPathFinderTests.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics; 2 | using NUnit.Framework; 3 | 4 | [TestFixture] 5 | public class AssemblyLocationTests 6 | { 7 | [Test] 8 | public void Foo() 9 | { 10 | var currentDirectory = AssemblyLocation.CurrentDirectory(); 11 | Debug.WriteLine(currentDirectory); 12 | } 13 | } 14 | 15 | -------------------------------------------------------------------------------- /FodyVSPackage/ContentsFinder.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | 3 | public class ContentsFinder 4 | { 5 | 6 | public string ContentFilesPath; 7 | 8 | public ContentsFinder() 9 | { 10 | var directoryName = Path.GetDirectoryName(GetType().Assembly.Location); 11 | ContentFilesPath = Path.Combine(directoryName, "ContentFiles"); 12 | } 13 | } -------------------------------------------------------------------------------- /Integration/Tests/WithOnlyInSolutionWeaverTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using NUnit.Framework; 3 | 4 | [TestFixture] 5 | public class WithOnlyInSolutionWeaverTest 6 | { 7 | [Test] 8 | public void EnsureTypeInjectedByModuleWeaver() 9 | { 10 | Assert.IsNotNull(Type.GetType("Weavers.TypeInjectedByModuleWeaver, WithOnlyInSolutionWeaver")); 11 | } 12 | } -------------------------------------------------------------------------------- /Fody/FileChangedChecker.cs: -------------------------------------------------------------------------------- 1 | public partial class Processor 2 | { 3 | 4 | public bool ShouldStartSinceFileChanged() 5 | { 6 | if (ContainsTypeChecker.Check(AssemblyFilePath, "ProcessedByFody")) 7 | { 8 | Logger.LogInfo("Did not process because file has already been processed."); 9 | return false; 10 | } 11 | return true; 12 | } 13 | } -------------------------------------------------------------------------------- /Fody/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Fody.Tests/AssemblyVersionReaderTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using NUnit.Framework; 4 | 5 | [TestFixture] 6 | public class AssemblyVersionReaderTests 7 | { 8 | [Test] 9 | [ExpectedException(typeof(WeavingException))] 10 | public void BadImage() 11 | { 12 | AssemblyVersionReader.GetAssemblyVersion( Path.Combine(Environment.CurrentDirectory, "BadAssembly.dll")); 13 | } 14 | } -------------------------------------------------------------------------------- /Fody/ProjectPathFinder.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | 3 | public partial class Processor 4 | { 5 | public void ValidateProjectPath() 6 | { 7 | if (!Directory.Exists(ProjectDirectory)) 8 | { 9 | throw new WeavingException(string.Format("ProjectDirectory \"{0}\" does not exist.", ProjectDirectory)); 10 | } 11 | Logger.LogInfo(string.Format("ProjectDirectory path is '{0}.'", ProjectDirectory)); 12 | } 13 | 14 | } -------------------------------------------------------------------------------- /FodyVSPackage/MsBuildXmlExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Xml.Linq; 3 | 4 | public static class MsBuildXmlExtensions 5 | { 6 | public const string BuildNamespace = "{http://schemas.microsoft.com/developer/msbuild/2003}"; 7 | 8 | public static IEnumerable BuildDescendants(this XContainer document, XName name) 9 | { 10 | return document.Descendants(BuildNamespace + name); 11 | } 12 | } -------------------------------------------------------------------------------- /Fody.Tests/DynamicTests.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | 3 | 4 | [TestFixture] 5 | public class DynamicTests 6 | { 7 | public string Foo; 8 | [Test] 9 | [Ignore] 10 | public void NoProperty() 11 | { 12 | dynamic x = "sdfsdf"; 13 | x.Foo = "sdfsdf"; 14 | } 15 | [Test] 16 | [Ignore] 17 | public void WrongType() 18 | { 19 | dynamic x = new DynamicTests(); 20 | x.Foo = 1; 21 | } 22 | } -------------------------------------------------------------------------------- /Fody.Tests/ShouldStartSinceFileChangedTests.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | 3 | [TestFixture] 4 | public class ShouldStartSinceFileChangedTests 5 | { 6 | [Test] 7 | public void Simple() 8 | { 9 | var processor = new Processor 10 | { 11 | AssemblyFilePath = GetType().Assembly.CodeBase.Replace("file:///", "") 12 | }; 13 | Assert.IsTrue(processor.ShouldStartSinceFileChanged()); 14 | } 15 | } -------------------------------------------------------------------------------- /Integration/Weavers/ModuleWeaver.cs: -------------------------------------------------------------------------------- 1 | using Mono.Cecil; 2 | 3 | public class ModuleWeaver 4 | { 5 | public ModuleDefinition ModuleDefinition { get; set; } 6 | 7 | public void Execute() 8 | { 9 | var typeDefinition = new TypeDefinition(GetType().Assembly.GetName().Name, "TypeInjectedBy" + GetType().Name, TypeAttributes.Public, ModuleDefinition.Import(typeof(object))); 10 | ModuleDefinition.Types.Add(typeDefinition); 11 | } 12 | } -------------------------------------------------------------------------------- /Integration/Weavers/NamedWeaver.cs: -------------------------------------------------------------------------------- 1 | using Mono.Cecil; 2 | 3 | public class NamedWeaver 4 | { 5 | public ModuleDefinition ModuleDefinition { get; set; } 6 | 7 | public void Execute() 8 | { 9 | var typeDefinition = new TypeDefinition(GetType().Assembly.GetName().Name, "TypeInjectedBy" + GetType().Name, TypeAttributes.Public, ModuleDefinition.Import(typeof (object))); 10 | ModuleDefinition.Types.Add(typeDefinition); 11 | } 12 | } -------------------------------------------------------------------------------- /FodyCommon/IInnerWeaver.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | public interface IInnerWeaver 4 | { 5 | string AssemblyFilePath { get; set; } 6 | string References { get; set; } 7 | string KeyFilePath { get; set; } 8 | List Weavers { get; set; } 9 | ILogger Logger { get; set; } 10 | string IntermediateDirectoryPath { get; set; } 11 | string SolutionDirectoryPath { get; set; } 12 | 13 | void Execute(); 14 | } -------------------------------------------------------------------------------- /Fody/WeaverAssemblyPathFinder.cs: -------------------------------------------------------------------------------- 1 | public partial class Processor 2 | { 3 | public string FindAssemblyPath(string weaverName) 4 | { 5 | var assemblyPath = addinFinder.FindAddinAssembly(weaverName); 6 | if (assemblyPath != null) 7 | { 8 | if (ContainsTypeChecker.Check(assemblyPath, "ModuleWeaver")) 9 | { 10 | return assemblyPath; 11 | } 12 | } 13 | return null; 14 | } 15 | } -------------------------------------------------------------------------------- /Fody.Tests/WeaverAssemblyPathFinderTests.cs: -------------------------------------------------------------------------------- 1 | using Moq; 2 | using NUnit.Framework; 3 | 4 | [TestFixture] 5 | public class WeaverAssemblyPathFinderTests 6 | { 7 | [Test] 8 | //TODO: 9 | public void Valid() 10 | { 11 | var finder = new Processor 12 | { 13 | ContainsTypeChecker = new Mock().Object, 14 | }; 15 | //finder.FindAssemblyPath("Name"); 16 | } 17 | } -------------------------------------------------------------------------------- /FodyIsolated.Tests/TypeFinderTest.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | 3 | [TestFixture] 4 | public class TypeFinderTest 5 | { 6 | 7 | [Test] 8 | public void Valid() 9 | { 10 | var assembly = typeof(InnerWeaver).Assembly; 11 | assembly.FindType("ModuleReader"); 12 | } 13 | 14 | [Test] 15 | public void NoTypeInAssembly() 16 | { 17 | var assembly = GetType().Assembly; 18 | Assert.IsNull(assembly.FindType("ModuleWeaver")); 19 | } 20 | } -------------------------------------------------------------------------------- /Fody/DomainAssemblyResolver.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Reflection; 4 | 5 | public static class DomainAssemblyResolver 6 | { 7 | public static void Connect() 8 | { 9 | AppDomain.CurrentDomain.AssemblyResolve += (sender, args) => GetAssembly(args.Name); 10 | } 11 | 12 | public static Assembly GetAssembly(string name) 13 | { 14 | return AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(x => x.FullName == name); 15 | } 16 | } -------------------------------------------------------------------------------- /Fody/AssemblyPathValidator.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | 3 | public partial class Processor 4 | { 5 | 6 | public void ValidatorAssemblyPath() 7 | { 8 | if (!File.Exists(AssemblyFilePath)) 9 | { 10 | throw new WeavingException(string.Format("AssemblyPath \"{0}\" does not exists. If you have not done a build you can ignore this error.", AssemblyFilePath)); 11 | } 12 | 13 | Logger.LogInfo(string.Format("AssemblyPath: {0}", AssemblyFilePath)); 14 | } 15 | 16 | } -------------------------------------------------------------------------------- /FodyCommon/ILogger.cs: -------------------------------------------------------------------------------- 1 | public interface ILogger 2 | { 3 | void SetCurrentWeaverName(string weaverName); 4 | void ClearWeaverName(); 5 | void LogInfo(string message); 6 | void LogWarning(string message); 7 | void LogWarning(string message, string file, int lineNumber, int columnNumber, int endLineNumber, int endColumnNumber); 8 | void LogError(string message, string file, int lineNumber, int columnNumber, int endLineNumber, int endColumnNumber); 9 | void LogError(string message); 10 | } 11 | 12 | -------------------------------------------------------------------------------- /FodyIsolated/ExceptionExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Text; 3 | 4 | public static class ExceptionExtensions 5 | { 6 | 7 | public static string GetLoaderMessages(this ReflectionTypeLoadException exception) 8 | { 9 | var stringBuilder = new StringBuilder(); 10 | foreach (var loaderException in exception.LoaderExceptions) 11 | { 12 | stringBuilder.AppendLine(loaderException.ToString()); 13 | } 14 | return stringBuilder.ToString(); 15 | } 16 | } -------------------------------------------------------------------------------- /Fody/AssemblyVersionReader.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | 4 | public class AssemblyVersionReader 5 | { 6 | public static Version GetAssemblyVersion(string path) 7 | { 8 | try 9 | { 10 | return AssemblyName.GetAssemblyName(path).Version; 11 | } 12 | catch (BadImageFormatException) 13 | { 14 | throw new WeavingException(String.Format("Could not get version number from '{0}'. It is possible the file is corrupt.", path)); 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /Fody/WeaverProjectContainsWeaverChecker.cs: -------------------------------------------------------------------------------- 1 | public partial class Processor 2 | { 3 | public bool WeaverProjectUsed; 4 | 5 | public bool WeaverProjectContainsType(string weaverName) 6 | { 7 | if (FoundWeaverProjectFile) 8 | { 9 | var check = ContainsTypeChecker.Check(WeaverAssemblyPath, weaverName); 10 | if (check) 11 | { 12 | WeaverProjectUsed = true; 13 | return true; 14 | } 15 | } 16 | return false; 17 | } 18 | } -------------------------------------------------------------------------------- /FodyVSPackage/AssemblyVersionReader.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | 4 | public class AssemblyVersionReader 5 | { 6 | public static Version GetAssemblyVersion(string path) 7 | { 8 | try 9 | { 10 | return AssemblyName.GetAssemblyName(path).Version; 11 | } 12 | catch (BadImageFormatException) 13 | { 14 | throw new Exception(String.Format("Could not get version number from '{0}'. It is possible the file is corrupt.", path)); 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /Fody/SolutionPathValidator.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | 3 | public partial class Processor 4 | { 5 | 6 | public void ValidateSolutionPath() 7 | { 8 | SolutionDirectoryPath = Path.GetFullPath(SolutionDirectoryPath); 9 | if (!Directory.Exists(SolutionDirectoryPath)) 10 | { 11 | throw new WeavingException(string.Format("SolutionDir \"{0}\" does not exist.", SolutionDirectoryPath)); 12 | } 13 | Logger.LogInfo(string.Format("SolutionDirectory path is '{0}'", SolutionDirectoryPath)); 14 | } 15 | } -------------------------------------------------------------------------------- /FodyVSPackage/UnsaveProjectChecker.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | using EnvDTE; 3 | 4 | public static class UnsaveProjectChecker 5 | { 6 | public static bool HasUnsavedPendingChanges(Project project) 7 | { 8 | if (project.Saved) 9 | { 10 | return false; 11 | } 12 | MessageBox.Show("This action needs to modify your project file. Please save your pending changes and try again.", string.Format("Please save '{0}' first.", project.Name), MessageBoxButton.OK); 13 | return true; 14 | } 15 | } -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text 3 | 4 | # Don't check these into the repo as LF to work around TeamCity bug 5 | *.xml -text 6 | *.targets -text 7 | 8 | # Custom for Visual Studio 9 | *.cs diff=csharp 10 | *.sln merge=union 11 | *.csproj merge=union 12 | *.vbproj merge=union 13 | *.fsproj merge=union 14 | *.dbproj merge=union 15 | 16 | # Denote all files that are truly binary and should not be modified. 17 | *.dll binary 18 | *.exe binary 19 | *.png binary 20 | *.ico binary 21 | *.snk binary 22 | -------------------------------------------------------------------------------- /Fody.Tests/SearchDirectories/AddToolsAssemblyLocationToAddinSearchTests.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | using NUnit.Framework; 3 | 4 | [TestFixture] 5 | public class AddToolsAssemblyLocationToAddinSearchTests 6 | { 7 | [Test] 8 | public void Simple() 9 | { 10 | var processor = new AddinFinder(); 11 | processor.AddToolsAssemblyLocationToAddinSearch(); 12 | var expected = Path.GetFullPath(Path.Combine(AssemblyLocation.CurrentDirectory(), @"..\..\")); 13 | Assert.AreEqual(expected, processor.AddinSearchPaths[0]+@"\"); 14 | } 15 | } -------------------------------------------------------------------------------- /FodyVsPackage.Tests/FodyDirectoryFinderTests.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | using NUnit.Framework; 3 | 4 | [TestFixture] 5 | public class FodyDirectoryFinderTests 6 | { 7 | 8 | [Test] 9 | public void Existing() 10 | { 11 | var fodyDir = FodyDirectoryFinder.TreeWalkForToolsFodyDir(AssemblyLocation.CurrentDirectory()); 12 | Assert.IsTrue(Directory.Exists(fodyDir)); 13 | } 14 | 15 | [Test] 16 | public void NotExisting() 17 | { 18 | Assert.IsNull(FodyDirectoryFinder.TreeWalkForToolsFodyDir(Path.GetTempPath())); 19 | } 20 | } -------------------------------------------------------------------------------- /Fody.Tests/FileChangedCheckerTests.cs: -------------------------------------------------------------------------------- 1 | using Moq; 2 | using NUnit.Framework; 3 | 4 | [TestFixture] 5 | public class FileChangedCheckerTests 6 | { 7 | [Test] 8 | public void Simple() 9 | { 10 | var processor = new Processor 11 | { 12 | ContainsTypeChecker = new Mock().Object, 13 | Logger = new Mock().Object, 14 | AssemblyFilePath = GetType().Assembly.Location 15 | }; 16 | Assert.IsTrue(processor.ShouldStartSinceFileChanged()); 17 | } 18 | } -------------------------------------------------------------------------------- /Tools/vs2010.sdk/CreatePkgDef.exe.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /Fody.Tests/SearchDirectories/AddToolsSolutionDirectoryToAddinSearchTests.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | 3 | [TestFixture] 4 | public class AddToolsSolutionDirectoryToAddinSearchTests 5 | { 6 | [Test] 7 | public void Simple() 8 | { 9 | var processor = new AddinFinder 10 | { 11 | SolutionDirectoryPath = "Solution" 12 | }; 13 | processor.AddToolsSolutionDirectoryToAddinSearch(); 14 | var searchPaths = processor.AddinSearchPaths; 15 | Assert.AreEqual(@"Solution\Tools", searchPaths[0]); 16 | } 17 | } -------------------------------------------------------------------------------- /FodyVsPackage.Tests/VersionCheckerTests.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | 3 | [TestFixture] 4 | public class VersionCheckerTests 5 | { 6 | [Test] 7 | public void InNotNewer() 8 | { 9 | var location = typeof (AssemblyLocation).Assembly.CodeBase.Replace("file:///", ""); 10 | Assert.IsFalse(VersionChecker.IsVersionNewer(location)); 11 | } 12 | [Test] 13 | public void IsNewer() 14 | { 15 | var location = GetType().Assembly.CodeBase.Replace("file:///", ""); 16 | Assert.IsTrue(VersionChecker.IsVersionNewer(location)); 17 | } 18 | } -------------------------------------------------------------------------------- /Fody/AddinFinder/AddToolsAssemblyLocationToAddinSearch.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | 3 | public partial class AddinFinder 4 | { 5 | public void AddToolsAssemblyLocationToAddinSearch() 6 | { 7 | var directoryInfo = new DirectoryInfo(AssemblyLocation.CurrentDirectory()).Parent; 8 | if (directoryInfo == null) 9 | { 10 | return; 11 | } 12 | directoryInfo = directoryInfo.Parent; 13 | if (directoryInfo == null) 14 | { 15 | return; 16 | } 17 | AddinSearchPaths.Add(directoryInfo.FullName); 18 | } 19 | } -------------------------------------------------------------------------------- /Fody.Tests/ContainsTypeCheckerTests.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | 3 | [TestFixture] 4 | public class ContainsTypeCheckerTests 5 | { 6 | [Test] 7 | public void Exists() 8 | { 9 | var checker = new ContainsTypeChecker(); 10 | var check = checker.Check(GetType().Assembly.Location, "ContainsTypeCheckerTests"); 11 | Assert.IsTrue(check); 12 | } 13 | 14 | [Test] 15 | public void NotExists() 16 | { 17 | var checker = new ContainsTypeChecker(); 18 | var check = checker.Check(GetType().Assembly.Location, "BadType"); 19 | Assert.IsFalse(check); 20 | } 21 | } -------------------------------------------------------------------------------- /packages/repositories.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /FodyVSPackage/Wpf/InverseBooleanConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | using System.Windows.Data; 4 | 5 | namespace Wpf 6 | { 7 | [ValueConversion(typeof (bool), typeof (bool))] 8 | public class InverseBooleanConverter : IValueConverter 9 | { 10 | 11 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 12 | { 13 | return !(bool) value; 14 | } 15 | 16 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 17 | { 18 | throw new NotSupportedException(); 19 | } 20 | 21 | } 22 | } -------------------------------------------------------------------------------- /FodyIsolated.Tests/IsolatedContainsTypeCheckerTests.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | 3 | [TestFixture] 4 | public class IsolatedContainsTypeCheckerTests 5 | { 6 | [Test] 7 | public void Exists() 8 | { 9 | var checker = new IsolatedContainsTypeChecker(); 10 | var check = checker.Check(GetType().Assembly.Location, "IsolatedContainsTypeCheckerTests"); 11 | Assert.IsTrue(check); 12 | } 13 | 14 | [Test] 15 | public void NotExists() 16 | { 17 | var checker = new IsolatedContainsTypeChecker(); 18 | var check = checker.Check(GetType().Assembly.Location, "BadType"); 19 | Assert.IsFalse(check); 20 | } 21 | } -------------------------------------------------------------------------------- /FodyVSPackage/MSBuildKiller.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | 4 | public class MSBuildKiller 5 | { 6 | public void Kill() 7 | { 8 | try 9 | { 10 | var id = Process.GetCurrentProcess().Id; 11 | foreach (var process in Process.GetProcessesByName("MSBuild")) 12 | { 13 | if (process.GetParentProcess().Id == id) 14 | { 15 | process.Kill(); 16 | } 17 | } 18 | } 19 | // ReSharper disable EmptyGeneralCatchClause 20 | catch (Exception) 21 | { 22 | } 23 | // ReSharper restore EmptyGeneralCatchClause 24 | } 25 | } -------------------------------------------------------------------------------- /Fody/AssemblyLocation.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | 4 | public static class AssemblyLocation 5 | { 6 | public static string CurrentDirectory() 7 | { 8 | //Use codebase because location fails for unit tests. 9 | // in unt tests returns a path like 10 | // C:\Users\Simon\AppData\Local\Temp\o2ehfpqw.x01\Fody.Tests\assembly\dl3\0e7cab25\21728d4f_da04cd01\Fody.dll 11 | // And that path contains only Fody.dll and no other assemblies 12 | var assembly = typeof(AssemblyLocation).Assembly; 13 | var uri = new UriBuilder(assembly.CodeBase); 14 | var path = Uri.UnescapeDataString(uri.Path); 15 | 16 | return Path.GetDirectoryName(path); 17 | } 18 | } -------------------------------------------------------------------------------- /FodyIsolated/InstanceConstructor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public static class InstanceConstructor 4 | { 5 | public static object ConstructInstance(this Type weaverType) 6 | { 7 | if (weaverType.IsAbstract || !weaverType.IsClass || !weaverType.IsPublic) 8 | { 9 | throw new WeavingException(String.Format("'{0}' is not public instance class.", weaverType.FullName)); 10 | } 11 | try 12 | { 13 | return Activator.CreateInstance(weaverType); 14 | } 15 | catch (Exception exception) 16 | { 17 | throw new Exception(String.Format("Could not construct instance of '{0}'.", weaverType.FullName), exception); 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /ChocolateyNuGet/Fody.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Fody 5 | $version$ 6 | Fody 7 | Simon Cropp 8 | Simon Cropp 9 | http://www.opensource.org/licenses/mit-license.php 10 | http://github.com/SimonCropp/Fody 11 | false 12 | Extensible tool for weaving .net assemblies. 13 | 14 | en-AU 15 | ILWeaving, Fody, Cecil 16 | 17 | -------------------------------------------------------------------------------- /Fody.Tests/SearchDirectories/AddNugetDirectoryToAddinSearchTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using NUnit.Framework; 4 | 5 | [TestFixture] 6 | public class AddNugetDirectoryToAddinSearchTests 7 | { 8 | [Test] 9 | public void Simple() 10 | { 11 | var processor = new AddinFinder 12 | { 13 | SolutionDirectoryPath = Environment.CurrentDirectory 14 | }; 15 | processor.AddNugetDirectoryToAddinSearch(); 16 | var searchPaths = processor.AddinSearchPaths; 17 | var expected = Path.Combine(Environment.CurrentDirectory, "Packages"); 18 | Assert.AreEqual(expected , searchPaths[0]); 19 | } 20 | 21 | } -------------------------------------------------------------------------------- /FodyVSPackage/ExceptionHandling/ExceptionDialog.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | using System.Windows.Interop; 4 | 5 | public class ExceptionDialog 6 | { 7 | 8 | [DllImport("user32.dll")] 9 | static extern IntPtr GetActiveWindow(); 10 | 11 | public void HandleException(Exception exception) 12 | { 13 | var model = new ExceptionWindowModel 14 | { 15 | ExceptionText = exception.ExceptionHierarchyToString(), 16 | }; 17 | var window = new ExceptionWindow(model); 18 | new WindowInteropHelper(window) 19 | { 20 | Owner = GetActiveWindow() 21 | }; 22 | window.ShowDialog(); 23 | } 24 | } -------------------------------------------------------------------------------- /Fody/AddinFinder/AddinFilesEnumerator.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.IO; 3 | using System.Linq; 4 | 5 | public partial class AddinFinder 6 | { 7 | List fodyFiles; 8 | 9 | 10 | public void CacheAllFodyAddinDlls() 11 | { 12 | fodyFiles = AddinSearchPaths 13 | .SelectMany(x => Directory.GetFiles(x, "*.Fody.dll", SearchOption.AllDirectories)) 14 | .ToList(); 15 | } 16 | 17 | public string FindAddinAssembly(string packageName) 18 | { 19 | var packageFileName = packageName + ".Fody.dll"; 20 | return fodyFiles.Where(x => x.EndsWith(packageFileName)) 21 | .OrderByDescending(AssemblyVersionReader.GetAssemblyVersion) 22 | .FirstOrDefault(); 23 | } 24 | } -------------------------------------------------------------------------------- /Fody.Tests/SearchDirectories/AddinDirectoriesTests.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Moq; 3 | using NUnit.Framework; 4 | 5 | [TestFixture] 6 | public class AddinDirectoriesTests 7 | { 8 | [Test] 9 | public void Simple() 10 | { 11 | var loggerMock = new Mock(); 12 | loggerMock.Setup(x => x.LogInfo("Directory added to addin search paths 'Path'.")); 13 | var processor = new AddinFinder 14 | { 15 | AddinSearchPaths = new List {"Path"}, 16 | Logger = loggerMock.Object 17 | }; 18 | processor.LogAddinSearchPaths(); 19 | loggerMock.Verify(); 20 | } 21 | } -------------------------------------------------------------------------------- /Tools/vs2010.sdk/ProjectItemsSchema.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /FodyVSPackage/ExceptionHandling/ExceptionWindow.xaml.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics; 2 | using System.Windows; 3 | 4 | 5 | public partial class ExceptionWindow 6 | { 7 | 8 | public ExceptionWindow(ExceptionWindowModel model) 9 | { 10 | Model = model; 11 | InitializeComponent(); 12 | DataContext = Model; 13 | } 14 | 15 | public ExceptionWindowModel Model { get; set; } 16 | 17 | 18 | void Copy(object sender, RoutedEventArgs e) 19 | { 20 | Clipboard.SetText(Model.ExceptionText); 21 | } 22 | 23 | 24 | void Close(object sender, RoutedEventArgs e) 25 | { 26 | Close(); 27 | } 28 | 29 | void LaunchIssues(object sender, RoutedEventArgs e) 30 | { 31 | Process.Start("https://github.com/SimonCropp/Fody/issues"); 32 | } 33 | } -------------------------------------------------------------------------------- /FodyVSPackage/PathEx.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Linq; 4 | 5 | public static class PathEx 6 | { 7 | public static string MakeRelativePath(string fromPath, string toPath) 8 | { 9 | if (fromPath.Last() != Path.DirectorySeparatorChar) 10 | { 11 | fromPath += Path.DirectorySeparatorChar; 12 | } 13 | if (toPath.Last() != Path.DirectorySeparatorChar) 14 | { 15 | toPath += Path.DirectorySeparatorChar; 16 | } 17 | var fromUri = new Uri(fromPath); 18 | var toUri = new Uri(toPath); 19 | 20 | var relativeUri = fromUri.MakeRelativeUri(toUri); 21 | var relativePath = Uri.UnescapeDataString(relativeUri.ToString()); 22 | return relativePath.Replace('/', Path.DirectorySeparatorChar); 23 | } 24 | } -------------------------------------------------------------------------------- /FodyIsolated/IsolatedContainsTypeChecker.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Security.Permissions; 4 | using Mono.Cecil; 5 | using SecurityAction = System.Security.Permissions.SecurityAction; 6 | 7 | public class IsolatedContainsTypeChecker : MarshalByRefObject, IContainsTypeChecker 8 | { 9 | 10 | // new DependencyLoader().LoadDependencies(); 11 | public bool Check(string assemblyPath, string typeName) 12 | { 13 | var module = ModuleDefinition.ReadModule(assemblyPath); 14 | var types = module.Types; 15 | return types.Any(x => x.Name == typeName); 16 | } 17 | 18 | [SecurityPermission(SecurityAction.Demand, Flags = SecurityPermissionFlag.Infrastructure)] 19 | public override object InitializeLifetimeService() 20 | { 21 | return null; 22 | } 23 | } -------------------------------------------------------------------------------- /Fody/XmlExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using System.Xml.Linq; 4 | 5 | public static class XmlExtensions 6 | { 7 | public static void StripNamespace(this XDocument document) 8 | { 9 | if (document.Root == null) 10 | { 11 | return; 12 | } 13 | foreach (var element in document.Root.DescendantsAndSelf()) 14 | { 15 | element.Name = element.Name.LocalName; 16 | element.ReplaceAttributes(GetAttributes(element).ToList()); 17 | } 18 | } 19 | 20 | static IEnumerable GetAttributes(XElement xElement) 21 | { 22 | return xElement.Attributes() 23 | .Where(x => !x.IsNamespaceDeclaration) 24 | .Select(x => new XAttribute(x.Name.LocalName, x.Value)); 25 | } 26 | 27 | } -------------------------------------------------------------------------------- /FodyIsolated/TypeFinder.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Reflection; 4 | 5 | public static class TypeFinder 6 | { 7 | public static Type FindType(this Assembly readAssembly, string typeName) 8 | { 9 | try 10 | { 11 | return readAssembly 12 | .GetTypes() 13 | .FirstOrDefault(x => x.Name == typeName); 14 | } 15 | catch (ReflectionTypeLoadException exception) 16 | { 17 | var message = string.Format( 18 | @"Could not load '{1}' from '{0}' due to ReflectionTypeLoadException. 19 | It is possible you need to update the package. 20 | exception.LoaderExceptions: 21 | {2}", readAssembly.FullName, typeName, exception.GetLoaderMessages()); 22 | throw new WeavingException(message); 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /Fody.Tests/ProjectWeaversFinderTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Moq; 3 | using NUnit.Framework; 4 | 5 | [TestFixture] 6 | public class ProjectWeaversFinderTests 7 | { 8 | [Test] 9 | public void NotFound() 10 | { 11 | var loggerMock = new Mock(); 12 | loggerMock.Setup(x => x.LogInfo(It.IsAny())); 13 | var logger = loggerMock.Object; 14 | var processor = new Processor 15 | { 16 | ProjectDirectory = Environment.CurrentDirectory, 17 | Logger = logger, 18 | SolutionDirectoryPath = Environment.CurrentDirectory 19 | }; 20 | processor.FindProjectWeavers(); 21 | Assert.IsEmpty(processor.ConfigFiles); 22 | loggerMock.Verify(); 23 | 24 | } 25 | } -------------------------------------------------------------------------------- /Integration/Tests/WithNugetAndInSolutionWeaversTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | using NUnit.Framework; 4 | using WithNugetAndInSolutionWeavers; 5 | 6 | [TestFixture] 7 | public class WithNugetAndInSolutionWeaversTest 8 | { 9 | [Test] 10 | public void EnsureTypeInjectedByModuleWeaver() 11 | { 12 | var types = Assembly.Load("WithNugetAndInSolutionWeavers").GetTypes(); 13 | 14 | Assert.IsNotNull(Type.GetType("Weavers.TypeInjectedByModuleWeaver, WithNugetAndInSolutionWeavers")); 15 | } 16 | [Test] 17 | public void EnsureTypeInjectedByNamedWeaver() 18 | { 19 | Assert.IsNotNull(Type.GetType("Weavers.TypeInjectedByNamedWeaver, WithNugetAndInSolutionWeavers")); 20 | } 21 | [Test] 22 | public void EnsureTypeChangedByNugetWeaver() 23 | { 24 | Assert.IsTrue(typeof(Class1).GetMethod("Method").IsVirtual); 25 | } 26 | } -------------------------------------------------------------------------------- /Tools/Pepita/PepitaGet.targets: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $(MSBuildProjectDirectory)\..\ 5 | 6 | 9 | 12 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /FodyVSPackage/ContainsFodyChecker.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Xml.Linq; 4 | 5 | public class ContainsFodyChecker 6 | { 7 | 8 | public bool Check(XDocument xDocument) 9 | { 10 | try 11 | { 12 | if (xDocument.BuildDescendants("Fody.WeavingTask").Any()) 13 | { 14 | return true; 15 | } 16 | return xDocument.BuildDescendants("Import") 17 | .Any(x => 18 | { 19 | var xAttribute = x.Attribute("Project"); 20 | return xAttribute != null && xAttribute.Value.EndsWith("Fody.targets"); 21 | }); 22 | } 23 | catch (Exception exception) 24 | { 25 | throw new Exception("Could not check project for weaving task.", exception); 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /Fody/WeaversHistory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | 5 | public static class WeaversHistory 6 | { 7 | public static Dictionary TimeStamps = new Dictionary(StringComparer.OrdinalIgnoreCase); 8 | 9 | public static bool HasChanged(IEnumerable weaverPaths) 10 | { 11 | var changed = false; 12 | foreach (var weaverPath in weaverPaths) 13 | { 14 | var newVersion = File.GetLastWriteTimeUtc(weaverPath); 15 | DateTime dateTime; 16 | if (TimeStamps.TryGetValue(weaverPath, out dateTime)) 17 | { 18 | if (dateTime != newVersion) 19 | { 20 | changed = true; 21 | } 22 | } 23 | TimeStamps[weaverPath] = newVersion; 24 | } 25 | return changed; 26 | } 27 | } -------------------------------------------------------------------------------- /FodyIsolated/ModuleWeaverRunner.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using Microsoft.CSharp.RuntimeBinder; 4 | 5 | public partial class InnerWeaver 6 | { 7 | 8 | public void RunWeaver(dynamic weaverInstance) 9 | { 10 | Logger.LogInfo(string.Format("Executing Weaver '{0}'.", ObjectTypeName.GetTypeName(weaverInstance))); 11 | 12 | var stopwatch = Stopwatch.StartNew(); 13 | try 14 | { 15 | weaverInstance.Execute(); 16 | } 17 | catch (RuntimeBinderException) 18 | { 19 | throw new WeavingException("ModuleWeaver must contain a method with the signature 'public void Execute()'."); 20 | } 21 | finally 22 | { 23 | stopwatch.Stop(); 24 | } 25 | Logger.LogInfo(string.Format("Finished {0}ms.{1}", stopwatch.ElapsedMilliseconds, Environment.NewLine)); 26 | } 27 | } 28 | 29 | -------------------------------------------------------------------------------- /Fody/ContainsTypeChecker.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public class ContainsTypeChecker 4 | { 5 | static IContainsTypeChecker containsTypeChecker; 6 | 7 | static ContainsTypeChecker() 8 | { 9 | var appDomainSetup = new AppDomainSetup 10 | { 11 | ApplicationBase = AssemblyLocation.CurrentDirectory(), 12 | }; 13 | var appDomain = AppDomain.CreateDomain("Fody.ContainsTypeChecker", null, appDomainSetup); 14 | var instanceAndUnwrap = appDomain.CreateInstanceAndUnwrap("FodyIsolated", "IsolatedContainsTypeChecker"); 15 | containsTypeChecker = (IContainsTypeChecker)instanceAndUnwrap; 16 | } 17 | 18 | 19 | //TODO: possibly cache based on file stamp to avoid cros domain call. need to profile. 20 | public bool Check(string assemblyPath, string typeName) 21 | { 22 | return containsTypeChecker.Check(assemblyPath, typeName); 23 | } 24 | 25 | } -------------------------------------------------------------------------------- /FodyVSPackage/FodyDirectoryFinder.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | 3 | public static class FodyDirectoryFinder 4 | { 5 | public static string TreeWalkForToolsFodyDir(string currentDirectory) 6 | { 7 | while (true) 8 | { 9 | var fodyDir = Path.Combine(currentDirectory, @"Tools\Fody"); 10 | if (Directory.Exists(fodyDir)) 11 | { 12 | return fodyDir; 13 | } 14 | try 15 | { 16 | var parent = Directory.GetParent(currentDirectory); 17 | if (parent == null) 18 | { 19 | break; 20 | } 21 | currentDirectory = parent.FullName; 22 | } 23 | catch 24 | { 25 | // trouble with tree walk. 26 | return null; 27 | } 28 | } 29 | return null; 30 | } 31 | } -------------------------------------------------------------------------------- /Fody/InstanceLinker/NoWeaversConfiguredInstanceLinker.cs: -------------------------------------------------------------------------------- 1 | public partial class Processor 2 | { 3 | 4 | public void ConfigureWhenNoWeaversFound() 5 | { 6 | if (!FoundWeaverProjectFile) 7 | { 8 | return; 9 | } 10 | if (WeaverProjectUsed) 11 | { 12 | return; 13 | } 14 | var weaverProjectContainsType = WeaverProjectContainsType("ModuleWeaver"); 15 | if (weaverProjectContainsType) 16 | { 17 | Logger.LogInfo("Found 'ModuleWeaver' in project 'Weavers' so will run that one."); 18 | var weaverEntry = new WeaverEntry 19 | { 20 | AssemblyPath = WeaverAssemblyPath, 21 | TypeName = "ModuleWeaver" 22 | }; 23 | Weavers.Add(weaverEntry); 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /FodyVsPackage.Tests/PathExTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Linq; 4 | using NUnit.Framework; 5 | 6 | [TestFixture] 7 | public class PathExTests 8 | { 9 | 10 | [Test] 11 | public void MakeRelativePath() 12 | { 13 | var parent = Directory.GetParent(Environment.CurrentDirectory).FullName; 14 | var makeRelativePath = PathEx.MakeRelativePath(parent, Environment.CurrentDirectory ); 15 | var expected = Environment.CurrentDirectory.Split(Path.DirectorySeparatorChar).Last() + Path.DirectorySeparatorChar; 16 | Assert.AreEqual(expected,makeRelativePath); 17 | } 18 | [Test] 19 | public void MakeRelativePathHigher() 20 | { 21 | var parent = Directory.GetParent(Environment.CurrentDirectory).FullName; 22 | var makeRelativePath = PathEx.MakeRelativePath(Environment.CurrentDirectory , parent ); 23 | Assert.AreEqual(@"..\",makeRelativePath); 24 | } 25 | } -------------------------------------------------------------------------------- /FodyVSPackage/CurrentProjectFinder.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using System.Runtime.InteropServices; 4 | using EnvDTE; 5 | using Microsoft.VisualStudio.Shell; 6 | 7 | public class CurrentProjectFinder 8 | { 9 | 10 | public List GetCurrentProjects() 11 | { 12 | var dte = (DTE) ServiceProvider.GlobalProvider.GetService(typeof (DTE)); 13 | if (dte.Solution == null) 14 | { 15 | return new List(); 16 | } 17 | if (string.IsNullOrEmpty(dte.Solution.FullName)) 18 | { 19 | return new List(); 20 | } 21 | try 22 | { 23 | var solutionProjects = (object[])dte.ActiveSolutionProjects; 24 | return solutionProjects.Cast().ToList(); 25 | } 26 | catch (COMException) 27 | { 28 | return new List(); 29 | } 30 | } 31 | 32 | } -------------------------------------------------------------------------------- /FodyIsolated/AssemblyReferenceFinder.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | 6 | public partial class InnerWeaver 7 | { 8 | public Dictionary ReferenceDictionary = new Dictionary(StringComparer.InvariantCultureIgnoreCase); 9 | public List SplitReferences; 10 | 11 | public void SplitUpReferences() 12 | { 13 | SplitReferences = References 14 | .Split(new[] {';'}, StringSplitOptions.RemoveEmptyEntries) 15 | .ToList(); 16 | SetRefDictionary(SplitReferences); 17 | Logger.LogInfo("Reference count=" + ReferenceDictionary.Count); 18 | } 19 | 20 | 21 | void SetRefDictionary(IEnumerable filePaths) 22 | { 23 | foreach (var filePath in filePaths) 24 | { 25 | ReferenceDictionary[Path.GetFileNameWithoutExtension(filePath)] = filePath; 26 | } 27 | } 28 | 29 | } -------------------------------------------------------------------------------- /FodyVsPackage.Tests/ExceptionWindowTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using NUnit.Framework; 3 | 4 | [TestFixture] 5 | public class ExceptionWindowTests 6 | { 7 | 8 | [Test] 9 | [Ignore] 10 | [STAThread] 11 | public void Launch() 12 | { 13 | var exception = GetException(); 14 | var model = new ExceptionWindowModel 15 | { 16 | ExceptionText = exception.ExceptionHierarchyToString(), 17 | }; 18 | var window = new ExceptionWindow(model); 19 | window.ShowDialog(); 20 | } 21 | 22 | Exception GetException() 23 | { 24 | try 25 | { 26 | ThrowException(); 27 | } 28 | catch (Exception exception) 29 | { 30 | return exception; 31 | } 32 | return null; 33 | } 34 | 35 | void ThrowException() 36 | { 37 | throw new NotImplementedException("Hello1", new NullReferenceException("Hello2")); 38 | } 39 | } -------------------------------------------------------------------------------- /FodyVsPackage.Tests/ExceptionExtensionsTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using NUnit.Framework; 3 | 4 | [TestFixture] 5 | public class ExceptionExtensionsTests 6 | { 7 | 8 | [Test] 9 | [Ignore] 10 | public void ExceptionHierarchyToString() 11 | { 12 | Exception exception1 = null; 13 | try 14 | { 15 | ThrowException1(); 16 | } 17 | catch (Exception exception) 18 | { 19 | exception1 = exception; 20 | } 21 | var exceptionAsString = exception1.ExceptionHierarchyToString(); 22 | //TODO: validate string 23 | } 24 | 25 | void ThrowException1() 26 | { 27 | try 28 | { 29 | ThrowException2(); 30 | } 31 | catch (Exception exception) 32 | { 33 | throw new Exception("Exceltion1", exception); 34 | } 35 | } 36 | 37 | void ThrowException2() 38 | { 39 | throw new InvalidOperationException("Exception2"); 40 | } 41 | } -------------------------------------------------------------------------------- /Fody.Tests/BuildLoggerTests.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Build.Framework; 2 | using NUnit.Framework; 3 | 4 | [TestFixture] 5 | public class BuildLoggerTests 6 | { 7 | [Test] 8 | public void NullMessageImportance() 9 | { 10 | var logger = new BuildLogger(null); 11 | Assert.AreEqual(MessageImportance.Low,logger.MessageImportance); 12 | } 13 | [Test] 14 | public void WhiteSpaceMessageImportance() 15 | { 16 | var logger = new BuildLogger(" "); 17 | Assert.AreEqual(MessageImportance.Low,logger.MessageImportance); 18 | } 19 | [Test] 20 | public void EmptyStringMessageImportance() 21 | { 22 | var logger = new BuildLogger(null); 23 | Assert.AreEqual(MessageImportance.Low,logger.MessageImportance); 24 | } 25 | [Test] 26 | public void MessageImportanceMessageImportance() 27 | { 28 | var logger = new BuildLogger("Normal"); 29 | Assert.AreEqual(MessageImportance.Normal, logger.MessageImportance); 30 | } 31 | } -------------------------------------------------------------------------------- /ChocolateyNuGet/chocolateyInstall.ps1: -------------------------------------------------------------------------------- 1 | function GetVSIXInstallerPath() 2 | { 3 | if( test-path $env:VS110COMNTOOLS ) 4 | { 5 | return join-path $env:VS110COMNTOOLS "../IDE/VSIXInstaller.exe" 6 | } 7 | if( test-path $env:VS100COMNTOOLS ) 8 | { 9 | return join-path $env:VS100COMNTOOLS "../IDE/VSIXInstaller.exe" 10 | } 11 | throw "Could not find VS100COMNTOOLS or VS110COMNTOOLS environment variables" 12 | } 13 | 14 | function Get-Script-Directory 15 | { 16 | $scriptInvocation = (Get-Variable MyInvocation -Scope 1).Value 17 | return Split-Path $scriptInvocation.MyCommand.Path 18 | } 19 | try 20 | { 21 | echo "Installing Fody" 22 | $vsixPath = join-path Get-Script-Directory FodyVsPackage.vsix 23 | 24 | $vsixInstallerPath = GetVSIXInstallerPath 25 | Start-Process -FilePath $vsixInstallerPath -ArgumentList "/q $vsixPath" -Wait -PassThru; 26 | 27 | Write-ChocolateySuccess "Fody" 28 | } 29 | catch 30 | { 31 | Write-ChocolateyFailure "Fody" "$($_.Exception.Message)" 32 | throw 33 | } 34 | -------------------------------------------------------------------------------- /Fody.Tests/InstanceLinker/NoWeaversConfiguredInstanceLinkerTests.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using Moq; 4 | using NUnit.Framework; 5 | 6 | [TestFixture] 7 | public class NoWeaversConfiguredInstanceLinkerTests 8 | { 9 | [Test] 10 | public void Simple() 11 | { 12 | var mock = new Mock(); 13 | mock.Setup(x => x.WeaverProjectContainsType("ModuleWeaver")) 14 | .Returns(true); 15 | mock.CallBase = true; 16 | var processor = mock.Object; 17 | 18 | processor.WeaverAssemblyPath = "Path"; 19 | processor.FoundWeaverProjectFile = true; 20 | processor.Weavers = new List(); 21 | processor.Logger = new Mock().Object; 22 | 23 | processor.ConfigureWhenNoWeaversFound(); 24 | 25 | var weaverEntry = processor.Weavers.First(); 26 | Assert.AreEqual("ModuleWeaver",weaverEntry.TypeName); 27 | Assert.AreEqual("Path",weaverEntry.AssemblyPath); 28 | mock.Verify(); 29 | } 30 | } -------------------------------------------------------------------------------- /FodyVSPackage/ProjectKind.cs: -------------------------------------------------------------------------------- 1 | public static class ProjectKind 2 | { 3 | const string CSharpProjectKind = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"; 4 | const string VBProjectKind = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"; 5 | const string FSharpProjectKind = "{F2A71F9B-5D33-465A-A702-920D77279786}"; 6 | const string SolutionFolderKind = "{66A26720-8FB5-11D2-AA7E-00C04F688DDE}"; 7 | 8 | public static bool IsSolutionFolderKind(string kind) 9 | { 10 | return kind.ToUpperInvariant() == SolutionFolderKind; 11 | } 12 | 13 | public static bool IsSupportedProjectKind(string kind) 14 | { 15 | var upperInvariant = kind.ToUpperInvariant(); 16 | if (CSharpProjectKind == upperInvariant) 17 | { 18 | return true; 19 | } 20 | if (VBProjectKind == upperInvariant) 21 | { 22 | return true; 23 | } 24 | if (FSharpProjectKind == upperInvariant) 25 | { 26 | return true; 27 | } 28 | return false; 29 | } 30 | } -------------------------------------------------------------------------------- /Fody.Tests/AddinFilesEnumeratorTests.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.IO; 3 | using NUnit.Framework; 4 | 5 | 6 | [TestFixture] 7 | public class AddinFilesEnumeratorTests 8 | { 9 | [Test] 10 | public void NotFound() 11 | { 12 | var processor = new AddinFinder 13 | { 14 | AddinSearchPaths = new List 15 | { 16 | Path.GetFullPath("Packages") 17 | } 18 | }; 19 | processor.CacheAllFodyAddinDlls(); 20 | Assert.IsNull(processor.FindAddinAssembly("DoesNotExist")); 21 | } 22 | 23 | [Test] 24 | public void Valid() 25 | { 26 | var processor = new AddinFinder 27 | { 28 | AddinSearchPaths = new List 29 | { 30 | Path.GetFullPath("Packages") 31 | } 32 | }; 33 | processor.CacheAllFodyAddinDlls(); 34 | Assert.IsNotNull( processor.FindAddinAssembly("SampleTask")); 35 | } 36 | } -------------------------------------------------------------------------------- /FodyVSPackage/MessageDisplayer.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.Shell; 2 | 3 | public class MessageDisplayer 4 | { 5 | ErrorListProvider errorProvider; 6 | 7 | 8 | public MessageDisplayer() 9 | { 10 | } 11 | 12 | public MessageDisplayer(ErrorListProvider errorProvider) 13 | { 14 | this.errorProvider = errorProvider; 15 | } 16 | 17 | public void ShowError(string error) 18 | { 19 | var errorTask = new ErrorTask 20 | { 21 | Category = TaskCategory.Misc, 22 | Text = error, 23 | CanDelete = true, 24 | }; 25 | errorProvider.Tasks.Add(errorTask); 26 | } 27 | 28 | public void ShowInfo(string info) 29 | { 30 | var task = new Task 31 | { 32 | Category = TaskCategory.Misc, 33 | Text = info, 34 | CanDelete = true, 35 | }; 36 | errorProvider.Tasks.Add(task); 37 | } 38 | 39 | } -------------------------------------------------------------------------------- /Fody.Tests/SolutionPathValidatorTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using Moq; 4 | using NUnit.Framework; 5 | 6 | [TestFixture] 7 | public class SolutionPathValidatorTests 8 | { 9 | [Test] 10 | public void Valid() 11 | { 12 | var loggerMock = new Mock(); 13 | 14 | loggerMock.Setup(x => x.LogInfo(It.Is(y => y.Contains(Environment.CurrentDirectory)))); 15 | var buildLogger = loggerMock.Object; 16 | 17 | var processor = new Processor 18 | { 19 | Logger = buildLogger, 20 | SolutionDirectoryPath = Environment.CurrentDirectory 21 | }; 22 | processor.ValidateSolutionPath(); 23 | loggerMock.Verify(); 24 | } 25 | 26 | [Test] 27 | public void InValid() 28 | { 29 | Assert.Throws(() => 30 | { 31 | 32 | var processor = new Processor 33 | { 34 | SolutionDirectoryPath = "baddir" 35 | }; 36 | processor.ValidateSolutionPath(); 37 | }, string.Format("SolutionDir \"{0}baddir\" does not exist.", Path.GetFullPath("baddir"))); 38 | } 39 | } -------------------------------------------------------------------------------- /FodyVSPackage/License.txt: -------------------------------------------------------------------------------- 1 | Open Source Initiative OSI - The MIT License 2 | http://www.opensource.org/licenses/mit-license.php 3 | Copyright (c) 2011 Simon Cropp 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /Integration/Weavers/Weavers.ncrunchproject: -------------------------------------------------------------------------------- 1 | 2 | false 3 | false 4 | false 5 | true 6 | false 7 | false 8 | false 9 | false 10 | true 11 | true 12 | false 13 | true 14 | true 15 | 60000 16 | 17 | 18 | AutoDetect 19 | -------------------------------------------------------------------------------- /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. -------------------------------------------------------------------------------- /FodyIsolated/SymbolsFinder.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | using Mono.Cecil.Cil; 3 | using Mono.Cecil.Mdb; 4 | using Mono.Cecil.Pdb; 5 | 6 | public partial class InnerWeaver 7 | { 8 | bool pdbFound; 9 | bool mdbFound; 10 | ISymbolReaderProvider debugReaderProvider; 11 | ISymbolWriterProvider debugWriterProvider; 12 | string mdbPath; 13 | string pdbPath; 14 | 15 | void GetSymbolProviders() 16 | { 17 | pdbPath = Path.ChangeExtension(AssemblyFilePath, "pdb"); 18 | if (File.Exists(pdbPath)) 19 | { 20 | pdbFound = true; 21 | debugReaderProvider = new PdbReaderProvider(); 22 | debugWriterProvider = new PdbWriterProvider(); 23 | Logger.LogInfo(string.Format("Found debug symbols at '{0}'.", pdbPath)); 24 | } 25 | 26 | mdbPath = AssemblyFilePath + ".mdb"; 27 | if (File.Exists(mdbPath)) 28 | { 29 | mdbFound = true; 30 | debugReaderProvider = new MdbReaderProvider(); 31 | debugWriterProvider = new MdbWriterProvider(); 32 | Logger.LogInfo(string.Format("Found debug symbols at '{0}'.", mdbPath)); 33 | } 34 | 35 | Logger.LogInfo("Found no debug symbols."); 36 | } 37 | 38 | } -------------------------------------------------------------------------------- /Integration/WithOnlyInSolutionWeaver/WithOnlyInSolutionWeaver.ncrunchproject: -------------------------------------------------------------------------------- 1 | 2 | false 3 | false 4 | false 5 | true 6 | false 7 | false 8 | false 9 | false 10 | true 11 | true 12 | false 13 | true 14 | true 15 | 60000 16 | 17 | 18 | AutoDetect 19 | -------------------------------------------------------------------------------- /FodyVSPackage/ExceptionHandling/ExceptionExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | 4 | public static class ExceptionExtensions 5 | { 6 | public static string ExceptionHierarchyToString(this Exception exception) 7 | { 8 | var stringBuilder = new StringBuilder(); 9 | var count = 0; 10 | 11 | while (exception != null) 12 | { 13 | if (count++ == 0) 14 | { 15 | stringBuilder.AppendLine("Top-level Exception"); 16 | } 17 | else 18 | { 19 | stringBuilder.AppendLine("Inner Exception " + (count - 1)); 20 | } 21 | 22 | stringBuilder.AppendLine("Type: " + exception.GetType()) 23 | .AppendLine("Message: " + exception.Message) 24 | .AppendLine("Source: " + exception.Source); 25 | 26 | if (exception.StackTrace != null) 27 | stringBuilder.AppendLine("Stack Trace: " + exception.StackTrace.Trim()); 28 | 29 | stringBuilder.AppendLine(); 30 | exception = exception.InnerException; 31 | } 32 | return stringBuilder.ToString().TrimEnd(); 33 | } 34 | } -------------------------------------------------------------------------------- /Integration/WithNugetAndInSolutionWeavers/WithNugetAndInSolutionWeavers.ncrunchproject: -------------------------------------------------------------------------------- 1 | 2 | false 3 | false 4 | false 5 | true 6 | false 7 | false 8 | false 9 | false 10 | true 11 | true 12 | false 13 | true 14 | true 15 | 60000 16 | 17 | 18 | AutoDetect 19 | -------------------------------------------------------------------------------- /Fody/WeaversXmlHistory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | 5 | public partial class Processor 6 | { 7 | public static Dictionary TimeStamps = new Dictionary(); 8 | 9 | public bool CheckForWeaversXmlChanged() 10 | { 11 | var changed = false; 12 | foreach (var configFile in ConfigFiles) 13 | { 14 | var timeStamp = File.GetLastWriteTimeUtc(configFile); 15 | DateTime dateTime; 16 | if (TimeStamps.TryGetValue(configFile, out dateTime)) 17 | { 18 | if (dateTime != timeStamp) 19 | { 20 | Logger.LogWarning(string.Format("A re-build is required to apply the changes from '{0}'.", configFile)); 21 | changed = true; 22 | } 23 | } 24 | else 25 | { 26 | TimeStamps[configFile] = timeStamp; 27 | } 28 | } 29 | return changed; 30 | } 31 | 32 | public void FlushWeaversXmlHistory() 33 | { 34 | foreach (var configFile in ConfigFiles) 35 | { 36 | TimeStamps[configFile] = File.GetLastWriteTimeUtc(configFile); 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /FodyIsolated/ModuleReader.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | using Mono.Cecil; 3 | 4 | public partial class InnerWeaver 5 | { 6 | public ModuleDefinition ModuleDefinition; 7 | 8 | public void ReadModule() 9 | { 10 | if (pdbFound) 11 | { 12 | using (var symbolStream = File.OpenRead(pdbPath)) 13 | { 14 | var readerParameters = new ReaderParameters 15 | { 16 | AssemblyResolver = this, 17 | ReadSymbols = pdbFound || mdbFound, 18 | SymbolReaderProvider = debugReaderProvider, 19 | SymbolStream = symbolStream 20 | }; 21 | ModuleDefinition = ModuleDefinition.ReadModule(AssemblyFilePath, readerParameters); 22 | } 23 | } 24 | else 25 | { 26 | var readerParameters = new ReaderParameters 27 | { 28 | AssemblyResolver = this, 29 | ReadSymbols = pdbFound || mdbFound, 30 | SymbolReaderProvider = debugReaderProvider, 31 | 32 | }; 33 | ModuleDefinition = ModuleDefinition.ReadModule(AssemblyFilePath, readerParameters); 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /FodyIsolated/ObjectTypeName.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | 4 | public static class ObjectTypeName 5 | { 6 | public static string GetTypeName(this object o) 7 | { 8 | var type = o.GetType(); 9 | return GetTypeName(type); 10 | } 11 | 12 | public static string GetTypeName(this Type type) 13 | { 14 | return string.Format("{1}, {0}", type.Assembly.GetName().Name, type.FullName); 15 | } 16 | 17 | public static PropertyInfo GetProperty(this Type type, string propertyName) 18 | { 19 | return type.GetProperty(propertyName, BindingFlags.SetProperty | BindingFlags.Instance | BindingFlags.Public, null, typeof (TProperty), new Type[]{}, null); 20 | } 21 | 22 | public static void SetProperty(this object instance, string propertyName, TProperty propertyValue) 23 | { 24 | var type = instance.GetType(); 25 | var property = type.GetProperty(propertyName); 26 | if (property == null) 27 | { 28 | return; 29 | } 30 | property.SetValue(instance, propertyValue, null); 31 | } 32 | 33 | public static string GetAssemblyName(this object o) 34 | { 35 | var type = o.GetType(); 36 | return type.Assembly.GetName().Name; 37 | } 38 | 39 | } -------------------------------------------------------------------------------- /FodyVSPackage/Wpf/EnumBooleanConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | using System.Windows; 4 | using System.Windows.Data; 5 | 6 | namespace Wpf 7 | { 8 | 9 | public class EnumBooleanConverter : IValueConverter 10 | { 11 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 12 | { 13 | var parameterString = parameter as string; 14 | if (parameterString == null) 15 | { 16 | return DependencyProperty.UnsetValue; 17 | } 18 | 19 | if (Enum.IsDefined(value.GetType(), value) == false) 20 | { 21 | return DependencyProperty.UnsetValue; 22 | } 23 | 24 | var parameterValue = Enum.Parse(value.GetType(), parameterString); 25 | 26 | return parameterValue.Equals(value); 27 | } 28 | 29 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 30 | { 31 | var parameterString = parameter as string; 32 | if (parameterString == null) 33 | { 34 | return DependencyProperty.UnsetValue; 35 | } 36 | 37 | return Enum.Parse(targetType, parameterString); 38 | } 39 | } 40 | 41 | } -------------------------------------------------------------------------------- /FodyIsolated/ModuleWriter.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics; 2 | using System.IO; 3 | using Mono.Cecil; 4 | using Mono.Cecil.Cil; 5 | using Mono.Cecil.Mdb; 6 | using Mono.Cecil.Pdb; 7 | using TypeAttributes = Mono.Cecil.TypeAttributes; 8 | 9 | public partial class InnerWeaver 10 | { 11 | 12 | 13 | public void WriteModule() 14 | { 15 | ModuleDefinition.Types.Add(new TypeDefinition(null, "ProcessedByFody", TypeAttributes.NotPublic | TypeAttributes.Abstract | TypeAttributes.Interface)); 16 | var assemblyPath = AssemblyFilePath; 17 | Logger.LogInfo(string.Format("Saving assembly to '{0}'.", assemblyPath)); 18 | 19 | var parameters = new WriterParameters 20 | { 21 | StrongNameKeyPair = StrongNameKeyPair, 22 | WriteSymbols = true, 23 | SymbolWriterProvider = debugWriterProvider, 24 | }; 25 | var startNew = Stopwatch.StartNew(); 26 | try 27 | { 28 | ModuleDefinition.Write(assemblyPath, parameters); 29 | } 30 | finally 31 | { 32 | startNew.Stop(); 33 | Logger.LogInfo(string.Format("Finished Saving {0}ms.", startNew.ElapsedMilliseconds)); 34 | } 35 | } 36 | 37 | } -------------------------------------------------------------------------------- /Fody/InstanceLinker/WeaversConfiguredInstanceLinker.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public partial class Processor 4 | { 5 | 6 | public void ConfigureWhenWeaversFound() 7 | { 8 | 9 | foreach (var weaverConfig in Weavers) 10 | { 11 | ProcessConfig(weaverConfig); 12 | } 13 | 14 | } 15 | 16 | public void ProcessConfig(WeaverEntry weaverConfig) 17 | { 18 | //support for diff names weavers when "In solution weaving" 19 | var weaverProjectContains = WeaverProjectContainsType(weaverConfig.AssemblyName); 20 | if (weaverProjectContains) 21 | { 22 | weaverConfig.AssemblyPath = WeaverAssemblyPath; 23 | weaverConfig.TypeName = weaverConfig.AssemblyName; 24 | return; 25 | } 26 | 27 | var assemblyPath = FindAssemblyPath(weaverConfig.AssemblyName); 28 | if (assemblyPath == null) 29 | { 30 | var searchPaths = string.Join(Environment.NewLine, addinFinder.AddinSearchPaths); 31 | var message = string.Format("Could not find a weaver named '{0}'. Tried:{1}{2}.", weaverConfig.AssemblyName, Environment.NewLine, searchPaths); 32 | throw new WeavingException(message); 33 | } 34 | weaverConfig.AssemblyPath = assemblyPath; 35 | weaverConfig.TypeName = "ModuleWeaver"; 36 | } 37 | } -------------------------------------------------------------------------------- /Fody/WeavingTask.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Build.Framework; 2 | using Microsoft.Build.Utilities; 3 | 4 | namespace Fody 5 | { 6 | 7 | public class WeavingTask : Task 8 | { 9 | [Required] 10 | public string AssemblyPath { set; get; } 11 | 12 | public string IntermediateDir { get; set; } 13 | public string KeyFilePath { get; set; } 14 | public string MessageImportance { set; get; } 15 | 16 | [Required] 17 | public string ProjectDirectory { get; set; } 18 | 19 | [Required] 20 | public string References { get; set; } 21 | 22 | [Required] 23 | public string SolutionDir { get; set; } 24 | 25 | public override bool Execute() 26 | { 27 | return new Processor 28 | { 29 | AssemblyFilePath = AssemblyPath, 30 | IntermediateDirectoryPath = IntermediateDir, 31 | KeyFilePath = KeyFilePath, 32 | MessageImportance = MessageImportance, 33 | ProjectDirectory = ProjectDirectory, 34 | References = References, 35 | SolutionDirectoryPath = SolutionDir, 36 | BuildEngine = BuildEngine 37 | }.Execute(); 38 | } 39 | 40 | } 41 | } 42 | 43 | -------------------------------------------------------------------------------- /FodyIsolated/AssemblyLoader.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Reflection; 5 | 6 | public partial class InnerWeaver 7 | { 8 | static Dictionary assemblies = new Dictionary(StringComparer.OrdinalIgnoreCase); 9 | 10 | public Assembly LoadAssembly(string assemblyPath) 11 | { 12 | Assembly assembly; 13 | if (assemblies.TryGetValue(assemblyPath, out assembly)) 14 | { 15 | Logger.LogInfo(string.Format("Loading '{0}' from cache.", assemblyPath)); 16 | return assembly; 17 | } 18 | Logger.LogInfo(string.Format("Loading '{0}' from disk.", assemblyPath)); 19 | return assemblies[assemblyPath] = LoadFromFile(assemblyPath); 20 | } 21 | 22 | public static Assembly LoadFromFile(string assemblyPath) 23 | { 24 | var pdbPath = Path.ChangeExtension(assemblyPath, "pdb"); 25 | var rawAssembly = File.ReadAllBytes(assemblyPath); 26 | if (File.Exists(pdbPath)) 27 | { 28 | return Assembly.Load(rawAssembly, File.ReadAllBytes(pdbPath)); 29 | } 30 | var mdbPath = Path.ChangeExtension(assemblyPath, "mdb"); 31 | if (File.Exists(mdbPath)) 32 | { 33 | return Assembly.Load(rawAssembly, File.ReadAllBytes(mdbPath)); 34 | } 35 | return Assembly.Load(rawAssembly); 36 | } 37 | 38 | } -------------------------------------------------------------------------------- /FodyVsPackage.Tests/ProjectRemoverTests.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | using NUnit.Framework; 3 | 4 | [TestFixture] 5 | public class ProjectRemoverTests 6 | { 7 | [Test] 8 | public void WithNoWeavingNotChanged() 9 | { 10 | var sourceProjectFile = Path.GetFullPath(@"TestProjects\ProjectWithNoWeaving.csproj"); 11 | var targetFile = Path.GetTempFileName(); 12 | File.Copy(sourceProjectFile, targetFile, true); 13 | try 14 | { 15 | new ProjectRemover(targetFile); 16 | Assert.AreEqual(FileReader.Read(@"TestProjects\ProjectWithNoWeaving.csproj"), FileReader.Read(targetFile)); 17 | } 18 | finally 19 | { 20 | File.Delete(targetFile); 21 | } 22 | } 23 | 24 | 25 | [Test] 26 | public void WeavingRemoved() 27 | { 28 | var sourceProjectFile = Path.GetFullPath(@"TestProjects\ProjectWithWeaving.csproj"); 29 | var targetFile = Path.GetTempFileName(); 30 | File.Copy(sourceProjectFile, targetFile, true); 31 | try 32 | { 33 | 34 | new ProjectRemover(targetFile); 35 | Assert.AreEqual(FileReader.Read(Path.GetFullPath(@"TestProjects\ProjectWithNoWeaving.csproj")), FileReader.Read(targetFile)); 36 | 37 | } 38 | finally 39 | { 40 | File.Delete(targetFile); 41 | } 42 | } 43 | 44 | } -------------------------------------------------------------------------------- /Fody/WeaverProjectFileFinder.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Linq; 4 | 5 | public partial class Processor 6 | { 7 | public string WeaverAssemblyPath; 8 | public bool FoundWeaverProjectFile; 9 | 10 | public void FindWeaverProjectFile() 11 | { 12 | GetValue(); 13 | if (WeaverAssemblyPath == null) 14 | { 15 | Logger.LogInfo("No Weaver project file found."); 16 | FoundWeaverProjectFile = false; 17 | } 18 | else 19 | { 20 | Logger.LogInfo(string.Format("Weaver project file found at '{0}'.", WeaverAssemblyPath)); 21 | FoundWeaverProjectFile = true; 22 | } 23 | } 24 | 25 | void GetValue() 26 | { 27 | var weaversBin = Path.Combine(SolutionDirectoryPath, @"Weavers\bin"); 28 | if (Directory.Exists(weaversBin)) 29 | { 30 | WeaverAssemblyPath = Directory.EnumerateFiles(weaversBin, "Weavers.dll", SearchOption.AllDirectories) 31 | .OrderByDescending(File.GetLastWriteTime) 32 | .FirstOrDefault(); 33 | return; 34 | } 35 | 36 | //Hack for ncrunch 37 | // 38 | WeaverAssemblyPath = References.Split(new[] {";"}, StringSplitOptions.RemoveEmptyEntries) 39 | .FirstOrDefault(x => x.EndsWith("Weavers.dll")); 40 | } 41 | 42 | } -------------------------------------------------------------------------------- /FodyVSPackage/ProjectRemover.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | using System.Linq; 3 | using System.Xml.Linq; 4 | 5 | public class ProjectRemover 6 | { 7 | XDocument xDocument; 8 | 9 | public ProjectRemover(string projectFile) 10 | { 11 | new FileInfo(projectFile).IsReadOnly = false; 12 | xDocument = XDocument.Load(projectFile); 13 | RemoveImport(); 14 | RemoveFodyWeaversXmlContent(); 15 | xDocument.Save(projectFile); 16 | DeleteFodyWeaversXmlFile(projectFile); 17 | } 18 | 19 | void RemoveFodyWeaversXmlContent() 20 | { 21 | xDocument.Descendants() 22 | .Where(x => (string)x.Attribute("Include")== "FodyWeavers.xml") 23 | .Remove(); 24 | } 25 | 26 | void DeleteFodyWeaversXmlFile(string projectFile) 27 | { 28 | var tasksPath = Path.Combine(Path.GetDirectoryName(projectFile), "FodyWeavers.xml"); 29 | if (File.Exists(tasksPath)) 30 | { 31 | new FileInfo(tasksPath).IsReadOnly = false; 32 | File.Delete(tasksPath); 33 | } 34 | } 35 | 36 | void RemoveImport() 37 | { 38 | xDocument.BuildDescendants("Import") 39 | .Where(x => 40 | { 41 | var xAttribute = x.Attribute("Project"); 42 | return xAttribute != null && xAttribute.Value.EndsWith("Fody.targets"); 43 | }) 44 | .Remove(); 45 | } 46 | } -------------------------------------------------------------------------------- /Fody.Tests/ProjectWeaversReaderTests/ProjectWeaversReaderTests.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.IO; 3 | using NUnit.Framework; 4 | 5 | 6 | [TestFixture] 7 | public class ProjectWeaversReaderTests 8 | { 9 | [Test] 10 | public void Simple() 11 | { 12 | var processor = new Processor(); 13 | processor.ConfigFiles.AddRange(GetPaths()); 14 | processor.ReadProjectWeavers(); 15 | var weavers = processor.Weavers; 16 | Assert.AreEqual(3, weavers.Count); 17 | Assert.AreEqual("SampleTask1", weavers[0].AssemblyName); 18 | Assert.AreEqual("", weavers[0].Element); 19 | Assert.AreEqual("SampleTask2", weavers[1].AssemblyName); 20 | Assert.AreEqual("", weavers[1].Element); 21 | Assert.AreEqual("SampleTask3", weavers[2].AssemblyName); 22 | Assert.AreEqual("", weavers[2].Element); 23 | 24 | } 25 | 26 | static IEnumerable GetPaths() 27 | { 28 | var currentDirectory = AssemblyLocation.CurrentDirectory(); 29 | yield return Path.Combine(currentDirectory, @"ProjectWeaversReaderTests\FodyWeavers1.xml"); 30 | yield return Path.Combine(currentDirectory, @"ProjectWeaversReaderTests\FodyWeavers2.xml"); 31 | yield return Path.Combine(currentDirectory, @"ProjectWeaversReaderTests\FodyWeavers3.xml"); 32 | } 33 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ################# 2 | ## Visual Studio 3 | ################# 4 | 5 | ## Ignore Visual Studio temporary files, build results, and 6 | ## files generated by popular Visual Studio add-ons. 7 | 8 | # User-specific files 9 | *.suo 10 | *.user 11 | *.sln.docstates 12 | *.pidb 13 | *.ncrunchsolution 14 | *.ncrunchproject 15 | *.DotSettings 16 | 17 | # Build results 18 | [Dd]ebug/ 19 | [Rr]elease/ 20 | *_i.c 21 | *_p.c 22 | *.ilk 23 | *.meta 24 | *.obj 25 | *.pch 26 | *.pgc 27 | *.pgd 28 | *.rsp 29 | *.sbr 30 | *.tlb 31 | *.tli 32 | *.tlh 33 | *.tmp 34 | *.vspscc 35 | .builds 36 | *.dotCover 37 | *test-results* 38 | 39 | 40 | ## If you have NuGet Package Restore enabled, uncomment this 41 | packages/ 42 | ForSample/ 43 | ChocolateyNuGetBuild/ 44 | 45 | # Visual Studio profiler 46 | *.psess 47 | *.vsp 48 | 49 | # ReSharper is a .NET coding add-in 50 | _ReSharper* 51 | 52 | # Others 53 | [Bb]in 54 | [Oo]bj 55 | sql 56 | TestResults 57 | *.Cache 58 | ClientBin 59 | stylecop.* 60 | ~$* 61 | *.dbmdl 62 | Generated_Code #added for RIA/Silverlight projects 63 | 64 | # Backup & report files from converting an old project file to a newer 65 | # Visual Studio version. Backup files are not needed, because we have git ;-) 66 | _UpgradeReport_Files/ 67 | Backup*/ 68 | UpgradeLog*.XML 69 | 70 | 71 | ############ 72 | ## Windows 73 | ############ 74 | 75 | # Windows image file caches 76 | Thumbs.db 77 | 78 | # Folder config file 79 | Desktop.ini 80 | 81 | 82 | Fody/.DS_Store 83 | 84 | .DS_Store 85 | 86 | *.userprefs 87 | -------------------------------------------------------------------------------- /FodyVSPackage/source.extension.vsixmanifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Fody 5 | Simon Cropp 6 | 1.8.14.0 7 | Extensible tool for weaving .net assemblies 8 | 1033 9 | https://github.com/SimonCropp/Fody 10 | License.txt 11 | false 12 | 13 | 14 | Ultimate 15 | Premium 16 | Pro 17 | 18 | 19 | Ultimate 20 | Premium 21 | Pro 22 | 23 | 24 | 25 | 26 | 27 | 28 | Visual Studio MPF 29 | 30 | 31 | 32 | |%CurrentProject%;PkgdefProjectOutputGroup| 33 | 34 | 35 | -------------------------------------------------------------------------------- /FodyIsolated.Tests/InstanceConstructorTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using NUnit.Framework; 3 | 4 | [TestFixture] 5 | public class InstanceConstructorTests 6 | { 7 | [Test] 8 | [ExpectedException(typeof(WeavingException), ExpectedMessage = "'System.Convert' is not public instance class.")] 9 | public void AbstractType() 10 | { 11 | typeof (Convert).ConstructInstance(); 12 | } 13 | 14 | [Test] 15 | [ExpectedException(typeof(WeavingException), ExpectedMessage = "'System.Console' is not public instance class.")] 16 | public void StaticType() 17 | { 18 | typeof(Console).ConstructInstance(); 19 | } 20 | 21 | [Test] 22 | [ExpectedException(typeof(WeavingException), ExpectedMessage = "'System.AttributeTargets' is not public instance class.")] 23 | public void Enum() 24 | { 25 | typeof(AttributeTargets).ConstructInstance(); 26 | } 27 | 28 | [Test] 29 | [ExpectedException(typeof(WeavingException), ExpectedMessage = "'InstanceConstructorTests+PrivateClass' is not public instance class.")] 30 | public void Private() 31 | { 32 | typeof(PrivateClass).ConstructInstance(); 33 | } 34 | 35 | class PrivateClass 36 | { 37 | } 38 | 39 | [Test] 40 | [ExpectedException(typeof(WeavingException), ExpectedMessage = "'InstanceConstructorTests+InternalClass' is not public instance class.")] 41 | public void Internal() 42 | { 43 | typeof(InternalClass).ConstructInstance(); 44 | } 45 | 46 | internal class InternalClass 47 | { 48 | } 49 | 50 | } -------------------------------------------------------------------------------- /FodyVSPackage/DisableMenuConfigure.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Runtime.InteropServices; 4 | 5 | public class DisableMenuConfigure 6 | { 7 | CurrentProjectFinder currentProjectFinder; 8 | MessageDisplayer messageDisplayer; 9 | ExceptionDialog exceptionDialog; 10 | 11 | public DisableMenuConfigure(CurrentProjectFinder currentProjectFinder, MessageDisplayer messageDisplayer, ExceptionDialog exceptionDialog) 12 | { 13 | this.exceptionDialog = exceptionDialog; 14 | this.messageDisplayer = messageDisplayer; 15 | this.currentProjectFinder = currentProjectFinder; 16 | } 17 | 18 | public void DisableCallback() 19 | { 20 | try 21 | { 22 | var projects = currentProjectFinder.GetCurrentProjects(); 23 | if (projects.Any(UnsaveProjectChecker.HasUnsavedPendingChanges)) 24 | { 25 | return; 26 | } 27 | foreach (var project in projects) 28 | { 29 | messageDisplayer.ShowInfo(string.Format("Fody: Removed from the project '{0}'. However no binary files will be removed in case they are being used by other projects.", project.Name)); 30 | new ProjectRemover(project.FullName); 31 | } 32 | } 33 | catch (COMException exception) 34 | { 35 | exceptionDialog.HandleException(exception); 36 | } 37 | catch (Exception exception) 38 | { 39 | exceptionDialog.HandleException(exception); 40 | } 41 | } 42 | 43 | } -------------------------------------------------------------------------------- /FodyVSPackage/AllProjectFinder.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using EnvDTE; 3 | using Microsoft.VisualStudio.Shell; 4 | 5 | public class AllProjectFinder 6 | { 7 | public IEnumerable GetAllProjects() 8 | { 9 | var projectList = new List(); 10 | var dte = (DTE) ServiceProvider.GlobalProvider.GetService(typeof (DTE)); 11 | foreach (Project project in dte.Solution.Projects) 12 | { 13 | if (ProjectKind.IsSupportedProjectKind(project.Kind)) 14 | { 15 | projectList.Add(project); 16 | } 17 | FindProjectInternal(project.ProjectItems, projectList); 18 | } 19 | return projectList; 20 | } 21 | 22 | static void FindProjectInternal(ProjectItems items, List projectList) 23 | { 24 | if (items == null) 25 | { 26 | return; 27 | } 28 | 29 | foreach (ProjectItem item in items) 30 | { 31 | Project project; 32 | if (item.SubProject != null) 33 | { 34 | project = item.SubProject; 35 | } 36 | else 37 | { 38 | project = item.Object as Project; 39 | } 40 | if (project != null) 41 | { 42 | if (ProjectKind.IsSupportedProjectKind(project.Kind)) 43 | { 44 | projectList.Add(project); 45 | } 46 | FindProjectInternal(project.ProjectItems, projectList); 47 | } 48 | } 49 | } 50 | 51 | } -------------------------------------------------------------------------------- /FodyVSPackage/ProcessExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.ComponentModel; 3 | using System.Diagnostics; 4 | using System.Runtime.InteropServices; 5 | 6 | public static class ProcessExtensions 7 | { 8 | [StructLayout(LayoutKind.Sequential)] 9 | public struct ProcessBasicInformation 10 | { 11 | public IntPtr Reserved1; 12 | public IntPtr PebBaseAddress; 13 | public IntPtr Reserved2_0; 14 | public IntPtr Reserved2_1; 15 | public IntPtr UniqueProcessId; 16 | public IntPtr InheritedFromUniqueProcessId; 17 | } 18 | 19 | [DllImport("ntdll.dll")] 20 | static extern int NtQueryInformationProcess(IntPtr processHandle, int processInformationClass, ref ProcessBasicInformation processInformation, int processInformationLength, out int returnLength); 21 | 22 | public static Process GetParentProcess(this Process process) 23 | { 24 | return GetParentProcess(process.Handle); 25 | } 26 | 27 | public static Process GetParentProcess(IntPtr handle) 28 | { 29 | var pbi = new ProcessBasicInformation(); 30 | int returnLength; 31 | var status = NtQueryInformationProcess(handle, 0, ref pbi, Marshal.SizeOf(pbi), out returnLength); 32 | if (status != 0) 33 | { 34 | throw new Win32Exception(status); 35 | } 36 | 37 | try 38 | { 39 | return Process.GetProcessById(pbi.InheritedFromUniqueProcessId.ToInt32()); 40 | } 41 | catch (ArgumentException) 42 | { 43 | // not found 44 | return null; 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /FodyVSPackage/TaskFileProcessor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | 4 | public class TaskFileProcessor 5 | { 6 | TaskFileReplacer taskFileReplacer; 7 | MessageDisplayer messageDisplayer; 8 | 9 | public TaskFileProcessor(TaskFileReplacer taskFileReplacer, MessageDisplayer messageDisplayer) 10 | { 11 | this.taskFileReplacer = taskFileReplacer; 12 | this.messageDisplayer = messageDisplayer; 13 | } 14 | 15 | public void ProcessTaskFile(string solutionDirectory) 16 | { 17 | try 18 | { 19 | var fodyDir = FodyDirectoryFinder.TreeWalkForToolsFodyDir(solutionDirectory); 20 | if (fodyDir != null) 21 | { 22 | var fodyFile = Path.Combine(fodyDir, "Fody.dll"); 23 | if (File.Exists(fodyFile)) 24 | { 25 | Check(fodyFile); 26 | return; 27 | } 28 | } 29 | foreach (var filePath in Directory.EnumerateFiles(solutionDirectory, "Fody.dll", SearchOption.AllDirectories)) 30 | { 31 | Check(filePath); 32 | } 33 | } 34 | catch (Exception exception) 35 | { 36 | messageDisplayer.ShowError(string.Format("Fody: An exception occurred while trying to check for updates.\r\nException: {0}.", exception)); 37 | } 38 | } 39 | 40 | void Check(string fodyFile) 41 | { 42 | if (VersionChecker.IsVersionNewer(fodyFile)) 43 | { 44 | taskFileReplacer.AddFile(Path.GetDirectoryName(fodyFile)); 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /FodyVSPackage/ExceptionHandling/ExceptionWindow.xaml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | An exception occurred in the Fody VSIX 15 | 16 | Please take a copy of the text and log a bug here 17 | 18 | 19 | Exception Detail: 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Fody/ProjectWeaversFinder.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.IO; 3 | 4 | public partial class Processor 5 | { 6 | public List ConfigFiles = new List(); 7 | 8 | public string SolutionConfigFilePath; 9 | 10 | 11 | public void FindProjectWeavers() 12 | { 13 | var fodyDirConfigFilePath = Path.Combine(AssemblyLocation.CurrentDirectory(), "FodyWeavers.xml"); 14 | if (File.Exists(fodyDirConfigFilePath)) 15 | { 16 | ConfigFiles.Add(fodyDirConfigFilePath); 17 | Logger.LogInfo(string.Format("Found path to weavers file '{0}'.", fodyDirConfigFilePath)); 18 | } 19 | 20 | var solutionConfigFilePath = Path.Combine(SolutionDirectoryPath, "FodyWeavers.xml"); 21 | if (File.Exists(solutionConfigFilePath)) 22 | { 23 | ConfigFiles.Add(solutionConfigFilePath); 24 | Logger.LogInfo(string.Format("Found path to weavers file '{0}'.", solutionConfigFilePath)); 25 | } 26 | 27 | var projectConfigFilePath = Path.Combine(ProjectDirectory, "FodyWeavers.xml"); 28 | if (File.Exists(projectConfigFilePath)) 29 | { 30 | ConfigFiles.Add(projectConfigFilePath); 31 | Logger.LogInfo(string.Format("Found path to weavers file '{0}'.", projectConfigFilePath)); 32 | } 33 | 34 | 35 | if (ConfigFiles.Count == 0) 36 | { 37 | var pathsSearched = string.Join("', '", fodyDirConfigFilePath, solutionConfigFilePath, projectConfigFilePath); 38 | Logger.LogInfo(string.Format("Could not find path to weavers file. Searched '{0}'.", pathsSearched)); 39 | } 40 | } 41 | 42 | } -------------------------------------------------------------------------------- /Fody.Tests/WeaverProjectFileFinderTests.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | using Moq; 3 | using NUnit.Framework; 4 | 5 | [TestFixture] 6 | public class WeaverProjectFileFinderTests 7 | { 8 | [Test] 9 | public void Found() 10 | { 11 | var currentDirectory = AssemblyLocation.CurrentDirectory(); 12 | var combine = Path.Combine(currentDirectory, @"..\..\WeaversProjectFileFinder\WithWeaver"); 13 | var loggerMock = new Mock(); 14 | loggerMock.Setup(x => x.LogInfo(It.IsAny())); 15 | 16 | var processor = new Processor 17 | { 18 | SolutionDirectoryPath = combine, 19 | Logger = loggerMock.Object 20 | }; 21 | 22 | processor.FindWeaverProjectFile(); 23 | Assert.IsTrue(processor.FoundWeaverProjectFile); 24 | loggerMock.Verify(); 25 | } 26 | 27 | //TODO: add tests where weavers is in references for ncrunch support 28 | [Test] 29 | public void NotFound() 30 | { 31 | var currentDirectory = AssemblyLocation.CurrentDirectory(); 32 | var combine = Path.Combine(currentDirectory, @"..\..\WeaversProjectFileFinder\WithNoWeaver"); 33 | var loggerMock = new Mock(); 34 | loggerMock.Setup(x => x.LogInfo(It.IsAny())); 35 | 36 | var processor = new Processor 37 | { 38 | SolutionDirectoryPath = combine, 39 | Logger = loggerMock.Object, 40 | References = "" 41 | }; 42 | 43 | processor.FindWeaverProjectFile(); 44 | Assert.IsFalse(processor.FoundWeaverProjectFile); 45 | loggerMock.Verify(); 46 | } 47 | } -------------------------------------------------------------------------------- /Fody.Tests/InstanceLinker/WeaversConfiguredInstanceLinkerTests.cs: -------------------------------------------------------------------------------- 1 | using Moq; 2 | using NUnit.Framework; 3 | 4 | [TestFixture] 5 | public class WeaversConfiguredInstanceLinkerTests 6 | { 7 | 8 | [Test] 9 | public void CustomWeaverInWeaversProject() 10 | { 11 | var mock = new Mock(); 12 | mock.Setup(x => x.WeaverProjectContainsType("CustomWeaver")) 13 | .Returns(true); 14 | mock.CallBase = true; 15 | var processor = mock.Object; 16 | processor.WeaverAssemblyPath = "Path"; 17 | 18 | 19 | var weaverConfig = new WeaverEntry 20 | { 21 | AssemblyName = "CustomWeaver" 22 | }; 23 | processor.ProcessConfig(weaverConfig); 24 | 25 | Assert.AreEqual("CustomWeaver", weaverConfig.TypeName); 26 | Assert.AreEqual("Path",weaverConfig.AssemblyPath); 27 | } 28 | 29 | [Test] 30 | public void WeaverInAddin() 31 | { 32 | var mock = new Mock(); 33 | mock.Setup(x => x.WeaverProjectContainsType("AddinName")) 34 | .Returns(false); 35 | mock.Setup(x => x.FindAssemblyPath("AddinName")).Returns("Path"); 36 | 37 | mock.CallBase = true; 38 | 39 | var processor = mock.Object; 40 | 41 | var weaverConfig = new WeaverEntry 42 | { 43 | AssemblyName = "AddinName" 44 | }; 45 | processor.ProcessConfig(weaverConfig); 46 | 47 | Assert.AreEqual("ModuleWeaver", weaverConfig.TypeName); 48 | Assert.AreEqual("Path",weaverConfig.AssemblyPath); 49 | mock.Verify(); 50 | } 51 | } -------------------------------------------------------------------------------- /Fody.Tests/WeaversHistoryTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Linq; 4 | using NUnit.Framework; 5 | 6 | [TestFixture] 7 | public class WeaversHistoryTests 8 | { 9 | [Test] 10 | public void AddNewFile() 11 | { 12 | var fileName = Path.GetTempFileName(); 13 | try 14 | { 15 | var hasChanged = WeaversHistory.HasChanged(new[] {fileName}); 16 | Assert.IsFalse(hasChanged); 17 | Assert.AreEqual(fileName, WeaversHistory.TimeStamps.First().Key); 18 | } 19 | finally 20 | { 21 | File.Delete(fileName); 22 | WeaversHistory.TimeStamps.Clear(); 23 | } 24 | } 25 | 26 | [Test] 27 | public void Changed() 28 | { 29 | var fileName = Path.GetTempFileName(); 30 | try 31 | { 32 | WeaversHistory.HasChanged(new[] {fileName}); 33 | File.SetLastWriteTimeUtc(fileName, DateTime.Now.AddHours(1)); 34 | var hasChanged = WeaversHistory.HasChanged(new[] {fileName}); 35 | Assert.IsTrue(hasChanged); 36 | } 37 | finally 38 | { 39 | File.Delete(fileName); 40 | WeaversHistory.TimeStamps.Clear(); 41 | } 42 | } 43 | 44 | [Test] 45 | public void Same() 46 | { 47 | var fileName = Path.GetTempFileName(); 48 | try 49 | { 50 | WeaversHistory.HasChanged(new[] { fileName }); 51 | 52 | var hasChanged = WeaversHistory.HasChanged(new[] { fileName }); 53 | Assert.IsFalse(hasChanged); 54 | } 55 | finally 56 | { 57 | File.Delete(fileName); 58 | WeaversHistory.TimeStamps.Clear(); 59 | } 60 | } 61 | } -------------------------------------------------------------------------------- /SampleTask.Fody/ModuleWeaver.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Xml.Linq; 3 | using Mono.Cecil; 4 | using Mono.Cecil.Cil; 5 | 6 | public class ModuleWeaver 7 | { 8 | // Will contain the full element XML from FodyWeavers.xml. OPTIONAL 9 | public XElement Config { get; set; } 10 | 11 | // Will log an informational message to MSBuild. OPTIONAL 12 | public Action LogInfo { get; set; } 13 | 14 | // Will log an warning message to MSBuild. OPTIONAL 15 | public Action LogWarning { get; set; } 16 | 17 | // Will log an warning message to MSBuild at a specific point in the code. OPTIONAL 18 | public Action LogWarningPoint { get; set; } 19 | 20 | // Will log an error message to MSBuild. OPTIONAL 21 | public Action LogError { get; set; } 22 | 23 | // Will log an error message to MSBuild at a specific point in the code. OPTIONAL 24 | public Action LogErrorPoint { get; set; } 25 | 26 | // An instance of Mono.Cecil.IAssemblyResolver for resolving assembly references. OPTIONAL 27 | public IAssemblyResolver AssemblyResolver { get; set; } 28 | 29 | // An instance of Mono.Cecil.ModuleDefinition for processing. REQUIRED 30 | public ModuleDefinition ModuleDefinition { get; set; } 31 | 32 | // Init logging delegates to make testing easier 33 | public ModuleWeaver() 34 | { 35 | LogInfo = m => { }; 36 | LogWarning = m => { }; 37 | LogWarningPoint = (m,p) => { }; 38 | LogError = m => { }; 39 | LogErrorPoint = (m, p) => { }; 40 | } 41 | 42 | public void Execute() 43 | { 44 | ModuleDefinition.Types.Add(new TypeDefinition("MyNamespace", "MyType", TypeAttributes.Public)); 45 | } 46 | } -------------------------------------------------------------------------------- /FodyIsolated/StrongNameKeyFinder.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | using System.Linq; 3 | using System.Reflection; 4 | 5 | public partial class InnerWeaver 6 | { 7 | public StrongNameKeyPair StrongNameKeyPair; 8 | 9 | public void FindStrongNameKey() 10 | { 11 | var keyFilePath = GetKeyFilePath(); 12 | if (keyFilePath != null) 13 | { 14 | if (!File.Exists(keyFilePath)) 15 | { 16 | throw new WeavingException(string.Format("KeyFilePath was defined but file does not exist. '{0}'.", keyFilePath)); 17 | } 18 | StrongNameKeyPair = new StrongNameKeyPair(File.OpenRead(keyFilePath)); 19 | } 20 | } 21 | 22 | 23 | string GetKeyFilePath() 24 | { 25 | if (KeyFilePath != null) 26 | { 27 | Logger.LogInfo(string.Format("Using strong name key from KeyFilePath '{0}'.", KeyFilePath)); 28 | return KeyFilePath; 29 | } 30 | //public AssemblyKeyFileAttribute(string keyFile) 31 | var assemblyKeyFileAttribute = ModuleDefinition 32 | .Assembly 33 | .CustomAttributes 34 | .FirstOrDefault(x => x.AttributeType.Name == "AssemblyKeyFileAttribute"); 35 | if (assemblyKeyFileAttribute != null) 36 | { 37 | var keyFileSuffix = (string) assemblyKeyFileAttribute.ConstructorArguments.First().Value; 38 | var ketFilePath = Path.Combine(IntermediateDirectoryPath, keyFileSuffix); 39 | Logger.LogInfo(string.Format("Using strong name key from [AssemblyKeyFileAttribute(\"{0}\")] '{1}'", keyFileSuffix, ketFilePath)); 40 | return ketFilePath ; 41 | } 42 | Logger.LogInfo("No strong name key found"); 43 | return null; 44 | } 45 | 46 | 47 | 48 | 49 | } -------------------------------------------------------------------------------- /FodyCommon.Tests/ToFriendlyStringTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using NUnit.Framework; 3 | 4 | [TestFixture] 5 | public class ToFriendlyStringTests 6 | { 7 | [Test] 8 | [Ignore] 9 | public void ToFriendlyName() 10 | { 11 | var currentDirectory = AssemblyLocation.CurrentDirectory().ToLowerInvariant() 12 | .Replace(@"bin\debug", string.Empty) 13 | .Replace(@"bin\release", string.Empty); 14 | try 15 | { 16 | ThrowException1(); 17 | 18 | } 19 | catch (Exception exception) 20 | { 21 | var friendlyString = exception.ToFriendlyString().ToLowerInvariant(); 22 | friendlyString = friendlyString 23 | .Replace(currentDirectory, string.Empty); 24 | var expected = @"an unhandled exception occurred: 25 | exception: 26 | foo 27 | stacktrace: 28 | at tofriendlystringtests.throwexception2() in tofriendlystringtests.cs:line 60 29 | at tofriendlystringtests.throwexception1() in tofriendlystringtests.cs:line 55 30 | at tofriendlystringtests.tofriendlyname() in tofriendlystringtests.cs:line 15 31 | source: 32 | fodycommon.tests 33 | targetsite: 34 | void throwexception2() 35 | "; 36 | Assert.AreEqual(expected, friendlyString); 37 | } 38 | } 39 | [Test] 40 | public void ToFriendlyNameWeaverException() 41 | { 42 | try 43 | { 44 | throw new WeavingException("Foo"); 45 | 46 | } 47 | catch (Exception exception) 48 | { 49 | var friendlyString = exception.ToFriendlyString(); 50 | Assert.AreEqual("Foo", friendlyString); 51 | } 52 | } 53 | 54 | void ThrowException1() 55 | { 56 | ThrowException2(); 57 | } 58 | 59 | void ThrowException2() 60 | { 61 | throw new Exception("Foo"); 62 | } 63 | } -------------------------------------------------------------------------------- /Fody/ProjectWeaversReader.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using System.Xml; 4 | using System.Xml.Linq; 5 | 6 | public partial class Processor 7 | { 8 | public List Weavers; 9 | 10 | public void ReadProjectWeavers() 11 | { 12 | if (Weavers != null) 13 | { 14 | return; 15 | } 16 | Weavers = new List(); 17 | foreach (var configFile in ConfigFiles) 18 | { 19 | var xDocument = GetDocument(configFile); 20 | foreach (var element in xDocument.Root.Elements()) 21 | { 22 | var assemblyName = element.Name.LocalName; 23 | var existing = Weavers.FirstOrDefault(x => x.AssemblyName == assemblyName); 24 | var index = Weavers.Count; 25 | if (existing != null) 26 | { 27 | index = Weavers.IndexOf(existing); 28 | Weavers.Remove(existing); 29 | } 30 | var weaverEntry = new WeaverEntry 31 | { 32 | Element = element.ToString(SaveOptions.OmitDuplicateNamespaces), 33 | AssemblyName = assemblyName 34 | }; 35 | Weavers.Insert(index, weaverEntry); 36 | } 37 | } 38 | } 39 | 40 | static XDocument GetDocument(string configFilePath) 41 | { 42 | try 43 | { 44 | return XDocument.Load(configFilePath); 45 | } 46 | catch (XmlException exception) 47 | { 48 | throw new WeavingException(string.Format("Could not read '{0}' because it has invalid xml. Message: '{1}'.", "FodyWeavers.xml", exception.Message)); 49 | } 50 | } 51 | } -------------------------------------------------------------------------------- /FodyIsolated.Tests/ModuleWeaverRunnerTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Xml.Linq; 3 | using Mono.Cecil; 4 | using Moq; 5 | using NUnit.Framework; 6 | 7 | 8 | [TestFixture] 9 | public class ModuleWeaverRunnerTests 10 | { 11 | 12 | [Test] 13 | public void Execute() 14 | { 15 | var moduleWeaver = new ValidModuleWeaver(); 16 | var moduleWeaverRunner = new InnerWeaver { Logger = new Mock().Object }; 17 | moduleWeaverRunner.RunWeaver(moduleWeaver); 18 | } 19 | 20 | [Test] 21 | [ExpectedException(typeof(WeavingException), ExpectedMessage = "ModuleWeaver must contain a method with the signature 'public void Execute()'.")] 22 | public void BadExecute() 23 | { 24 | var moduleWeaver = new BadExecuteWithParamsModuleWeaver(); 25 | var moduleWeaverRunner = new InnerWeaver { Logger = new Mock().Object }; 26 | moduleWeaverRunner.RunWeaver( moduleWeaver); 27 | } 28 | 29 | [Test] 30 | [ExpectedException(typeof (WeavingException))] 31 | public void NoExecute() 32 | { 33 | var moduleWeaverRunner = new InnerWeaver { Logger = new Mock().Object }; 34 | moduleWeaverRunner.RunWeaver("sdf"); 35 | } 36 | 37 | public class ValidModuleWeaver 38 | { 39 | public XElement Config { get; set; } 40 | public Action LogInfo = s => { }; 41 | public Action LogWarning = s => { }; 42 | public IAssemblyResolver AssemblyResolver { get; set; } 43 | public ModuleDefinition ModuleDefinition; 44 | public bool ExecuteCalled; 45 | 46 | public void Execute() 47 | { 48 | ExecuteCalled = true; 49 | } 50 | } 51 | 52 | public class BadExecuteWithParamsModuleWeaver 53 | { 54 | public void Execute(string foo) 55 | { 56 | } 57 | } 58 | } -------------------------------------------------------------------------------- /FodyVsPackage.Tests/ProjectInjectorTests.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | using NUnit.Framework; 3 | 4 | [TestFixture] 5 | public class ProjectInjectorTests 6 | { 7 | [Test] 8 | public void WithNoWeaving() 9 | { 10 | var sourceProjectFile = Path.GetFullPath(@"TestProjects\ProjectWithNoWeaving.csproj"); 11 | var targetFile = Path.GetTempFileName(); 12 | File.Copy(sourceProjectFile, targetFile, true); 13 | 14 | try 15 | { 16 | var injector = new ProjectInjector 17 | { 18 | ProjectFile = targetFile, 19 | FodyToolsDirectory = @"$(SolutionDir)\Tools\Fody\" 20 | }; 21 | injector.Execute(); 22 | 23 | Assert.AreEqual(FileReader.Read(@"TestProjects\ProjectWithWeaving.csproj"), FileReader.Read(targetFile)); 24 | } 25 | finally 26 | { 27 | File.Delete(targetFile); 28 | } 29 | 30 | } 31 | 32 | [Test] 33 | public void WithExistingWeaving() 34 | { 35 | var sourceProjectFile = Path.GetFullPath(@"TestProjects\ProjectWithWeaving.csproj"); 36 | var targetFile = Path.GetTempFileName(); 37 | File.Copy(sourceProjectFile, targetFile, true); 38 | 39 | try 40 | { 41 | var injector = new ProjectInjector 42 | { 43 | ProjectFile = targetFile, 44 | }; 45 | injector.Execute(); 46 | 47 | var source = FileReader.Read(sourceProjectFile); 48 | var target = FileReader.Read(targetFile); 49 | Assert.AreEqual(source, target); 50 | } 51 | finally 52 | { 53 | File.Delete(targetFile); 54 | } 55 | 56 | } 57 | 58 | 59 | } -------------------------------------------------------------------------------- /Fody/AddinFinder/AddinSearchDirectories.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.IO; 3 | using System.Linq; 4 | 5 | public partial class AddinFinder 6 | { 7 | public List AddinSearchPaths = new List(); 8 | 9 | public void FindAddinDirectories() 10 | { 11 | AddNugetDirectoryToAddinSearch(); 12 | AddToolsSolutionDirectoryToAddinSearch(); 13 | AddToolsAssemblyLocationToAddinSearch(); 14 | LogAddinSearchPaths(); 15 | CacheAllFodyAddinDlls(); 16 | } 17 | 18 | public void AddToolsSolutionDirectoryToAddinSearch() 19 | { 20 | var solutionDirToolsDirectory =Path.Combine(SolutionDirectoryPath, "Tools"); 21 | AddinSearchPaths.Add(solutionDirToolsDirectory); 22 | } 23 | 24 | public void AddNugetDirectoryToAddinSearch() 25 | { 26 | var packagesPathFromConfig = NugetConfigReader.GetPackagesPathFromConfig(SolutionDirectoryPath); 27 | if (packagesPathFromConfig != null) 28 | { 29 | AddinSearchPaths.Add(packagesPathFromConfig); 30 | } 31 | AddinSearchPaths.Add(Path.Combine(SolutionDirectoryPath, "Packages")); 32 | } 33 | 34 | 35 | public ILogger Logger; 36 | public string SolutionDirectoryPath; 37 | 38 | public void LogAddinSearchPaths() 39 | { 40 | AddinSearchPaths = AddinSearchPaths.Distinct().ToList(); 41 | foreach (var searchPath in AddinSearchPaths.ToList()) 42 | { 43 | if (Directory.Exists(searchPath)) 44 | { 45 | Logger.LogInfo(string.Format("Directory added to addin search paths '{0}'.", searchPath)); 46 | } 47 | else 48 | { 49 | AddinSearchPaths.Remove(searchPath); 50 | Logger.LogInfo(string.Format("Could not search for addins in '{0}' because it does not exist", searchPath)); 51 | } 52 | 53 | } 54 | } 55 | 56 | } -------------------------------------------------------------------------------- /FodyVSPackage/Styles.xaml: -------------------------------------------------------------------------------- 1 | 4 | 7 | 8 | 12 | 13 | 16 | 17 | 20 | 24 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /FodyVSPackage/MenuConfigure.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.ComponentModel.Design; 3 | using Microsoft.VisualStudio.Shell; 4 | 5 | public class MenuConfigure 6 | { 7 | OleMenuCommand configureCommand; 8 | OleMenuCommand disableCommand; 9 | ConfigureMenuCallback configureMenuCallback; 10 | DisableMenuConfigure disableMenuConfigure; 11 | IMenuCommandService menuCommandService; 12 | MenuStatusChecker menuStatusChecker; 13 | Guid cmdSet = new Guid("c0886fa2-b3c2-4546-9cd1-ed18d53cab98"); 14 | 15 | public MenuConfigure(ConfigureMenuCallback configureMenuCallback, DisableMenuConfigure disableMenuConfigure, IMenuCommandService menuCommandService, MenuStatusChecker menuStatusChecker) 16 | { 17 | this.configureMenuCallback = configureMenuCallback; 18 | this.disableMenuConfigure = disableMenuConfigure; 19 | this.menuCommandService = menuCommandService; 20 | this.menuStatusChecker = menuStatusChecker; 21 | } 22 | 23 | public void RegisterMenus() 24 | { 25 | CreateConfigCommand(); 26 | CreateDisableCommand(); 27 | } 28 | 29 | void CreateDisableCommand() 30 | { 31 | var disableCommandId = new CommandID(cmdSet, 2); 32 | disableCommand = new OleMenuCommand(delegate { disableMenuConfigure.DisableCallback(); }, disableCommandId) 33 | { 34 | Enabled = false 35 | }; 36 | disableCommand.BeforeQueryStatus += delegate { menuStatusChecker.DisableCommandStatusCheck(disableCommand); }; 37 | menuCommandService.AddCommand(disableCommand); 38 | } 39 | 40 | void CreateConfigCommand() 41 | { 42 | var configureCommandId = new CommandID(cmdSet, 1); 43 | configureCommand = new OleMenuCommand(delegate { configureMenuCallback.ConfigureCallback(); }, configureCommandId); 44 | configureCommand.BeforeQueryStatus += delegate { menuStatusChecker.ConfigureCommandStatusCheck(configureCommand); }; 45 | menuCommandService.AddCommand(configureCommand); 46 | } 47 | } -------------------------------------------------------------------------------- /Fody.Tests/XmlExtensionsTests.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics; 2 | using System.Linq; 3 | using System.Xml.Linq; 4 | using NUnit.Framework; 5 | 6 | 7 | [TestFixture] 8 | public class XmlExtensionsTests 9 | { 10 | [Test] 11 | public void Simple() 12 | { 13 | var xDocument = XDocument.Parse( 14 | @" 15 | 16 | African Coffee Table 17 | 80 18 | 120 19 | 20 | "); 21 | xDocument.StripNamespace(); 22 | Assert.AreEqual( 23 | @" 24 | 25 | African Coffee Table 26 | 80 27 | 120 28 |
29 |
".Replace("\r\n", "\n"), xDocument.ToString().Replace("\r\n", "\n")); 30 | } 31 | 32 | [Test] 33 | public void QueryWithNamespace() 34 | { 35 | var xDocument = XDocument.Parse( 36 | @" 37 | 38 | African Coffee Table 39 | 80 40 | 120 41 | 42 | "); 43 | var qualifiedName = XName.Get("table", "http://www.w3schools.com/furniture"); 44 | var tables = xDocument.Descendants(qualifiedName); 45 | Debug.WriteLine(tables.Count()); 46 | } 47 | 48 | [Test] 49 | public void QueryWithNoNamespace() 50 | { 51 | var xDocument = XDocument.Parse( 52 | @" 53 | 54 | African Coffee Table 55 | 80 56 | 120 57 | 58 | "); 59 | xDocument.StripNamespace(); 60 | var tables = xDocument.Descendants("table"); 61 | Debug.WriteLine(tables.Count()); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /FodyVSPackage/ProjectInjector.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | using System.Linq; 3 | using System.Xml.Linq; 4 | 5 | public class ProjectInjector 6 | { 7 | public string ProjectFile; 8 | public string FodyToolsDirectory; 9 | XDocument xDocument; 10 | 11 | public void Execute() 12 | { 13 | new FileInfo(ProjectFile).IsReadOnly = false; 14 | xDocument = XDocument.Load(ProjectFile); 15 | InjectImport(); 16 | InjectWeaversContent(); 17 | xDocument.Save(ProjectFile); 18 | } 19 | 20 | void InjectWeaversContent() 21 | { 22 | var exists = xDocument.Descendants() 23 | .Any(x => 24 | { 25 | var xAttribute = x.Attribute("Include"); 26 | return xAttribute != null && xAttribute.Value == "FodyWeavers.xml"; 27 | }); 28 | if (exists) 29 | { 30 | return; 31 | } 32 | 33 | var itemGroup = xDocument.BuildDescendants("ItemGroup").FirstOrDefault(); 34 | if (itemGroup == null) 35 | { 36 | itemGroup = new XElement(MsBuildXmlExtensions.BuildNamespace + "ItemGroup"); 37 | xDocument.Root.Add(itemGroup); 38 | } 39 | itemGroup.Add(new XElement(MsBuildXmlExtensions.BuildNamespace + "None", new XAttribute("Include", "FodyWeavers.xml"))); 40 | } 41 | 42 | void InjectImport() 43 | { 44 | // 45 | var exists = xDocument 46 | .BuildDescendants("Import") 47 | .Any(x => 48 | { 49 | var xAttribute = x.Attribute("Project"); 50 | return xAttribute != null && xAttribute.Value.EndsWith("Fody.targets"); 51 | }); 52 | if (exists) 53 | { 54 | return; 55 | } 56 | var importAttribute = new XAttribute("Project", Path.Combine(FodyToolsDirectory, "Fody.targets")); 57 | xDocument.Root.Add(new XElement(MsBuildXmlExtensions.BuildNamespace + "Import", importAttribute)); 58 | 59 | } 60 | } -------------------------------------------------------------------------------- /FodyCommon/ExceptionExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | 4 | public static class ExceptionExtensions 5 | { 6 | public static string ToFriendlyString(this Exception exception) 7 | { 8 | if (exception.GetType().Name == "WeavingException") 9 | { 10 | return exception.Message; 11 | } 12 | 13 | var stringBuilder = new StringBuilder(); 14 | stringBuilder.Append("An unhandled exception occurred:"); 15 | stringBuilder.Append(Environment.NewLine); 16 | stringBuilder.Append("Exception:"); 17 | stringBuilder.Append(Environment.NewLine); 18 | while (exception != null) 19 | { 20 | stringBuilder.Append(exception.Message); 21 | stringBuilder.Append(Environment.NewLine); 22 | 23 | foreach (var i in exception.Data) 24 | { 25 | stringBuilder.Append("Data :"); 26 | stringBuilder.Append(i); 27 | stringBuilder.Append(Environment.NewLine); 28 | } 29 | 30 | if (exception.StackTrace != null) 31 | { 32 | stringBuilder.Append("StackTrace:"); 33 | stringBuilder.Append(Environment.NewLine); 34 | stringBuilder.Append(exception.StackTrace); 35 | stringBuilder.Append(Environment.NewLine); 36 | } 37 | 38 | if (exception.Source != null) 39 | { 40 | stringBuilder.Append("Source:"); 41 | stringBuilder.Append(Environment.NewLine); 42 | stringBuilder.Append(exception.Source); 43 | stringBuilder.Append(Environment.NewLine); 44 | } 45 | 46 | if (exception.TargetSite != null) 47 | { 48 | stringBuilder.Append("TargetSite:"); 49 | stringBuilder.Append(Environment.NewLine); 50 | stringBuilder.Append(exception.TargetSite); 51 | stringBuilder.Append(Environment.NewLine); 52 | } 53 | 54 | exception = exception.InnerException; 55 | } 56 | 57 | return stringBuilder.ToString(); 58 | } 59 | } -------------------------------------------------------------------------------- /FodyVsPackage.Tests/TestProjects/ProjectWithNoWeaving.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | AnyCPU 6 | 8.0.30703 7 | 2.0 8 | {6E6A991E-85F6-494C-8E54-E829B8AB1462} 9 | Library 10 | ProjectName 11 | ProjectName 12 | v4.0 13 | 512 14 | 15 | 16 | true 17 | full 18 | false 19 | bin\Debug\ 20 | DEBUG;TRACE 21 | prompt 22 | 4 23 | 24 | 25 | pdbonly 26 | true 27 | bin\Release\ 28 | TRACE 29 | prompt 30 | 4 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /FodyVsPackage.Tests/TestProjects/ProjectWithWeaving.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | AnyCPU 6 | 8.0.30703 7 | 2.0 8 | {6E6A991E-85F6-494C-8E54-E829B8AB1462} 9 | Library 10 | ProjectName 11 | ProjectName 12 | v4.0 13 | 512 14 | 15 | 16 | true 17 | full 18 | false 19 | bin\Debug\ 20 | DEBUG;TRACE 21 | prompt 22 | 4 23 | 24 | 25 | pdbonly 26 | true 27 | bin\Release\ 28 | TRACE 29 | prompt 30 | 4 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /NugetConfigReader.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | using System.Linq; 3 | using System.Xml.Linq; 4 | 5 | public static class NugetConfigReader 6 | { 7 | 8 | public static string GetPackagesPathFromConfig(string currentDirectory) 9 | { 10 | while (true) 11 | { 12 | var packagePath = GetPackagePath(Path.Combine(currentDirectory, "nuget.config")); 13 | if (packagePath != null) 14 | { 15 | return packagePath; 16 | } 17 | packagePath = GetPackagePath(Path.Combine(currentDirectory, ".nuget", "nuget.config")); 18 | if (packagePath != null) 19 | { 20 | return packagePath; 21 | } 22 | try 23 | { 24 | var directoryInfo = Directory.GetParent(currentDirectory); 25 | if (directoryInfo == null) 26 | { 27 | return null; 28 | } 29 | currentDirectory = directoryInfo.FullName; 30 | } 31 | catch 32 | { 33 | // trouble with tree walk. ignore 34 | return null; 35 | } 36 | } 37 | } 38 | 39 | public static string GetPackagePath(string nugetConfigPath) 40 | { 41 | if (File.Exists(nugetConfigPath)) 42 | { 43 | var xDocument = XDocument.Load(nugetConfigPath); 44 | var repositoryPath = xDocument.Descendants("repositoryPath") 45 | .Select(x => x.Value) 46 | .FirstOrDefault(x => !string.IsNullOrWhiteSpace(x)); 47 | if (repositoryPath != null) 48 | { 49 | return Path.Combine(Path.GetDirectoryName(nugetConfigPath), repositoryPath); 50 | } 51 | repositoryPath = xDocument.Descendants("add") 52 | .Where(x => (string)x.Attribute("key") == "repositoryPath") 53 | .Select(x => x.Attribute("value")) 54 | .Where(x => x != null) 55 | .Select(x => x.Value) 56 | .FirstOrDefault(); 57 | if (repositoryPath != null) 58 | { 59 | return Path.Combine(Path.GetDirectoryName(nugetConfigPath), repositoryPath); 60 | } 61 | } 62 | return null; 63 | } 64 | } -------------------------------------------------------------------------------- /Fody.Tests/WeaversXmlHistoryTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Linq; 4 | using Moq; 5 | using NUnit.Framework; 6 | 7 | [TestFixture] 8 | public class WeaversXmlHistoryTests 9 | { 10 | [Test] 11 | public void AddNewFile() 12 | { 13 | var fileName = Path.GetTempFileName(); 14 | try 15 | { 16 | var processor = new Processor(); 17 | processor.ConfigFiles.Add(fileName); 18 | processor.CheckForWeaversXmlChanged(); 19 | 20 | Assert.AreEqual(File.GetLastWriteTimeUtc(fileName), Processor.TimeStamps.First().Value); 21 | } 22 | finally 23 | { 24 | File.Delete(fileName); 25 | Processor.TimeStamps.Clear(); 26 | } 27 | } 28 | 29 | [Test] 30 | public void AddExistingFile() 31 | { 32 | var fileName = Path.GetTempFileName(); 33 | try 34 | { 35 | var processor = new Processor(); 36 | processor.ConfigFiles.Add(fileName); 37 | processor.CheckForWeaversXmlChanged(); 38 | processor.CheckForWeaversXmlChanged(); 39 | 40 | Assert.AreEqual(File.GetLastWriteTimeUtc(fileName), Processor.TimeStamps.First().Value); 41 | } 42 | finally 43 | { 44 | File.Delete(fileName); 45 | Processor.TimeStamps.Clear(); 46 | } 47 | } 48 | 49 | [Test] 50 | public void AddChangedFile() 51 | { 52 | var fileName = Path.GetTempFileName(); 53 | try 54 | { 55 | var expected = File.GetLastWriteTimeUtc(fileName); 56 | var loggerMock = new Mock(); 57 | loggerMock.Setup(x => x.LogInfo(It.IsAny())); 58 | 59 | var processor = new Processor 60 | { 61 | Logger = loggerMock.Object 62 | }; 63 | processor.ConfigFiles.Add(fileName); 64 | processor.CheckForWeaversXmlChanged(); 65 | File.SetLastWriteTimeUtc(fileName, DateTime.Now.AddHours(1)); 66 | processor.CheckForWeaversXmlChanged(); 67 | 68 | loggerMock.Verify(); 69 | 70 | Assert.AreEqual(expected, Processor.TimeStamps.First().Value); 71 | } 72 | finally 73 | { 74 | File.Delete(fileName); 75 | Processor.TimeStamps.Clear(); 76 | } 77 | } 78 | } -------------------------------------------------------------------------------- /FodyVSPackage/FodyVSPackagePackage.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | using System.ComponentModel.Design; 4 | using Microsoft.VisualStudio.Shell; 5 | 6 | [ProvideAutoLoad("F1536EF8-92EC-443C-9ED7-FDADF150DA82")] //SolutionExists 7 | [ProvideAutoLoad("ADFC4E64-0397-11D1-9F4E-00A0C911004F ")] //NoSolution 8 | [ProvideAutoLoad("4d7a79c7-e2e3-4140-93cc-f0e68a6cae56")] 9 | [PackageRegistration(UseManagedResourcesOnly = true)] 10 | [InstalledProductRegistration("#110", "#112", "1.0", IconResourceID = 400)] 11 | [ProvideMenuResource("Menus.ctmenu", 1)] 12 | [Guid("16486db9-230d-4ab0-bef3-e5f81d4175eb")] 13 | public sealed class FodyVSPackagePackage : Package 14 | { 15 | 16 | protected override void Initialize() 17 | { 18 | base.Initialize(); 19 | var exceptionDialog = new ExceptionDialog(); 20 | try 21 | { 22 | var menuCommandService = (IMenuCommandService) GetService(typeof (IMenuCommandService)); 23 | var errorListProvider = new ErrorListProvider(ServiceProvider.GlobalProvider); 24 | 25 | var currentProjectFinder = new CurrentProjectFinder(); 26 | var contentsFinder = new ContentsFinder(); 27 | var configureMenuCallback = new ConfigureMenuCallback(currentProjectFinder, contentsFinder, exceptionDialog); 28 | var messageDisplayer = new MessageDisplayer(errorListProvider); 29 | var disableMenuConfigure = new DisableMenuConfigure(currentProjectFinder, messageDisplayer, exceptionDialog); 30 | var containsFodyChecker = new ContainsFodyChecker(); 31 | var menuStatusChecker = new MenuStatusChecker(currentProjectFinder, exceptionDialog, containsFodyChecker); 32 | new MenuConfigure(configureMenuCallback, disableMenuConfigure, menuCommandService, menuStatusChecker).RegisterMenus(); 33 | var taskFileReplacer = new TaskFileReplacer(messageDisplayer, contentsFinder); 34 | var taskFileProcessor = new TaskFileProcessor(taskFileReplacer, messageDisplayer); 35 | var msBuildKiller = new MSBuildKiller(); 36 | new SolutionEvents(taskFileProcessor, exceptionDialog, msBuildKiller).RegisterSolutionEvents(); 37 | new TaskFileReplacer(messageDisplayer, contentsFinder).CheckForFilesToUpdate(); 38 | } 39 | catch (Exception exception) 40 | { 41 | exceptionDialog.HandleException(exception); 42 | } 43 | } 44 | 45 | } -------------------------------------------------------------------------------- /Integration/WithNugetWeavers/WithNugetWeavers.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | AnyCPU 6 | 8.0.30703 7 | 2.0 8 | {4744FEC7-AE13-4A20-81C6-BBB837C19B5F} 9 | Library 10 | Properties 11 | WithNugetWeavers 12 | WithNugetWeavers 13 | v4.0 14 | 512 15 | 16 | 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | pdbonly 27 | true 28 | bin\Release\ 29 | TRACE 30 | prompt 31 | 4 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /Integration/WithOnlyInSolutionWeaver/WithOnlyInSolutionWeaver.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | AnyCPU 6 | 8.0.30703 7 | 2.0 8 | {4D1BF1C8-5C19-4A95-BEFF-6F8D67FF7B87} 9 | Library 10 | Properties 11 | WithOnlyInSolutionWeaver 12 | WithOnlyInSolutionWeaver 13 | v4.0 14 | 512 15 | 16 | 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | pdbonly 27 | true 28 | bin\Release\ 29 | TRACE 30 | prompt 31 | 4 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | {3f4c62f3-f582-452f-b455-0cd5c89d96cf} 45 | Weavers 46 | false 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /Tools/vs2010.sdk/Microsoft.VsSDK.Cpp.targets: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | $(BeforeResourceCompileTargets); 22 | VSCTCompile 23 | 24 | 25 | $(AfterBuildLinkTargets); 26 | IsolatedShellFiles; 27 | RegisterStubTarget; 28 | _VsixCleanRecordFileWrites 29 | 30 | 31 | 32 | 35 | 36 | 37 | 38 | 39 | 40 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /FodyVSPackage/FodyVSPackage.vsct: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 25 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | Fody 42 | Fody 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /Integration/WithNugetAndInSolutionWeavers/WithNugetAndInSolutionWeavers.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | AnyCPU 6 | 8.0.30703 7 | 2.0 8 | {7DDD6A9E-7D35-4D5B-8B60-D9D32F3D521A} 9 | Library 10 | Properties 11 | WithNugetAndInSolutionWeavers 12 | WithNugetAndInSolutionWeavers 13 | v4.0 14 | 512 15 | 16 | 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | pdbonly 27 | true 28 | bin\Release\ 29 | TRACE 30 | prompt 31 | 4 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | Designer 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | {3f4c62f3-f582-452f-b455-0cd5c89d96cf} 56 | Weavers 57 | false 58 | 59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /FodyIsolated.Tests/WeaverInitialiserTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Xml.Linq; 4 | using Mono.Cecil; 5 | using Mono.Cecil.Cil; 6 | using NUnit.Framework; 7 | 8 | [TestFixture] 9 | public class WeaverInitialiserTests 10 | { 11 | [Test] 12 | public void ValidProps() 13 | { 14 | var moduleDefinition = ModuleDefinition.CreateModule("Foo", ModuleKind.Dll); 15 | 16 | var innerWeaver = new InnerWeaver 17 | { 18 | AssemblyFilePath = "AssemblyFilePath", 19 | SolutionDirectoryPath = "SolutionDirectoryPath", 20 | ReferenceDictionary = new Dictionary { { "Ref1;Ref2","Path1" } }, 21 | ModuleDefinition = moduleDefinition, 22 | 23 | }; 24 | 25 | var weaverEntry = new WeaverEntry 26 | { 27 | Element = "", 28 | AssemblyPath = @"c:\FakePath\Assembly.dll" 29 | }; 30 | var moduleWeaver = new ValidModuleWeaver(); 31 | innerWeaver.SetProperties(weaverEntry, moduleWeaver); 32 | 33 | Assert.IsNotNull(moduleWeaver.LogInfo); 34 | Assert.IsNotNull(moduleWeaver.LogWarning); 35 | Assert.IsNotNull(moduleWeaver.LogWarningPoint); 36 | Assert.IsNotNull(moduleWeaver.LogError); 37 | Assert.IsNotNull(moduleWeaver.LogErrorPoint); 38 | // Assert.IsNotEmpty(moduleWeaver.References); 39 | Assert.AreEqual(moduleDefinition, moduleWeaver.ModuleDefinition); 40 | Assert.AreEqual(innerWeaver, moduleWeaver.AssemblyResolver); 41 | Assert.AreEqual(@"c:\FakePath",moduleWeaver.AddinDirectoryPath); 42 | Assert.AreEqual("AssemblyFilePath", moduleWeaver.AssemblyFilePath); 43 | Assert.AreEqual("SolutionDirectoryPath", moduleWeaver.SolutionDirectoryPath); 44 | } 45 | 46 | 47 | public class ValidModuleWeaver 48 | { 49 | public XElement Config { get; set; } 50 | // public List References { get; set; } 51 | public string AssemblyFilePath { get; set; } 52 | public string AddinDirectoryPath { get; set; } 53 | public Action LogInfo { get; set; } 54 | public Action LogWarning { get; set; } 55 | public Action LogWarningPoint { get; set; } 56 | public Action LogError { get; set; } 57 | public Action LogErrorPoint { get; set; } 58 | public IAssemblyResolver AssemblyResolver { get; set; } 59 | public ModuleDefinition ModuleDefinition { get; set; } 60 | public string SolutionDirectoryPath { get; set; } 61 | 62 | public bool ExecuteCalled; 63 | 64 | public void Execute() 65 | { 66 | ExecuteCalled = true; 67 | } 68 | } 69 | } -------------------------------------------------------------------------------- /Fody.targets: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | $(NCrunchOriginalSolutionDir) 7 | 8 | 9 | 10 | 11 | $(SolutionDir) 12 | 13 | 14 | 15 | 16 | $(MSBuildProjectDirectory)\..\ 17 | 18 | 19 | 20 | 21 | $(ProjectDir)$(IntermediateOutputPath) 22 | Low 23 | 24 | 27 | 31 | 40 | 43 | 47 | 51 | 52 | 53 | 57 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /Tools/Fody/Fody.targets: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | $(NCrunchOriginalSolutionDir) 7 | 8 | 9 | 10 | 11 | $(SolutionDir) 12 | 13 | 14 | 15 | 16 | $(MSBuildProjectDirectory)\..\ 17 | 18 | 19 | 20 | 21 | $(ProjectDir)$(IntermediateOutputPath) 22 | Low 23 | 24 | 27 | 31 | 40 | 43 | 47 | 51 | 52 | 53 | 57 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /FodyIsolated/InnerWeaver.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Security.Permissions; 4 | 5 | public partial class InnerWeaver : MarshalByRefObject, IInnerWeaver 6 | { 7 | public string AssemblyFilePath { get; set; } 8 | public string SolutionDirectoryPath { get; set; } 9 | public string References { get; set; } 10 | public List Weavers { get; set; } 11 | public string KeyFilePath { get; set; } 12 | public ILogger Logger { get; set; } 13 | public string IntermediateDirectoryPath { get; set; } 14 | 15 | public void Execute() 16 | { 17 | try 18 | { 19 | // AppDomain.CurrentDomain.AssemblyResolve += (sender, args) => ResolveAssembly(args); 20 | SplitUpReferences(); 21 | 22 | GetSymbolProviders(); 23 | ReadModule(); 24 | 25 | SetWeaverProperties(); 26 | 27 | Logger.LogInfo(""); 28 | foreach (var weaverInstance in WeaverInstances) 29 | { 30 | var weaverName = ObjectTypeName.GetAssemblyName(weaverInstance); 31 | Logger.SetCurrentWeaverName(weaverName); 32 | try 33 | { 34 | RunWeaver(weaverInstance); 35 | } 36 | catch (Exception exception) 37 | { 38 | Logger.LogError(exception.ToFriendlyString()); 39 | return; 40 | } 41 | finally 42 | { 43 | Logger.ClearWeaverName(); 44 | } 45 | } 46 | 47 | FindStrongNameKey(); 48 | WriteModule(); 49 | 50 | } 51 | catch (Exception exception) 52 | { 53 | Logger.LogError(exception.ToFriendlyString()); 54 | } 55 | } 56 | 57 | //Assembly ResolveAssembly(ResolveEventArgs resolveEventArgs) 58 | //{ 59 | // var replace = resolveEventArgs.RequestingAssembly.GetName().Name.Replace(".Fody", string.Empty); 60 | // var weaverEntry = Weavers.FirstOrDefault(x => x.AssemblyName == replace); 61 | // if (weaverEntry == null) 62 | // { 63 | // return null; 64 | // } 65 | // var directoryName = Path.GetDirectoryName(weaverEntry.AssemblyPath); 66 | 67 | // var dllPathToLoad = Path.Combine(directoryName, new AssemblyName(resolveEventArgs.Name).Name+".dll"); 68 | // if (File.Exists(dllPathToLoad)) 69 | // { 70 | // var readAllBytes = File.ReadAllBytes(dllPathToLoad); 71 | // return Assembly.Load(readAllBytes); 72 | // } 73 | // return null; 74 | //} 75 | 76 | 77 | [SecurityPermission(SecurityAction.Demand, Flags = SecurityPermissionFlag.Infrastructure)] 78 | public override object InitializeLifetimeService() 79 | { 80 | return null; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /FodyVSPackage/SolutionEvents.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using EnvDTE; 4 | using Microsoft.VisualStudio; 5 | using Microsoft.VisualStudio.Shell; 6 | using Microsoft.VisualStudio.Shell.Interop; 7 | 8 | public class SolutionEvents : IVsSolutionEvents 9 | { 10 | TaskFileProcessor taskFileProcessor; 11 | ExceptionDialog exceptionDialog; 12 | MSBuildKiller msBuildKiller; 13 | 14 | public SolutionEvents(TaskFileProcessor taskFileProcessor, ExceptionDialog exceptionDialog, MSBuildKiller msBuildKiller) 15 | { 16 | this.taskFileProcessor = taskFileProcessor; 17 | this.exceptionDialog = exceptionDialog; 18 | this.msBuildKiller = msBuildKiller; 19 | } 20 | 21 | public void RegisterSolutionEvents() 22 | { 23 | uint cookie; 24 | var vsSolution = (IVsSolution) ServiceProvider.GlobalProvider.GetService(typeof (IVsSolution)); 25 | vsSolution.AdviseSolutionEvents(this, out cookie); 26 | } 27 | 28 | 29 | public int OnAfterOpenSolution(object pUnkReserved, int fNewSolution) 30 | { 31 | try 32 | { 33 | var dte = (DTE) ServiceProvider.GlobalProvider.GetService(typeof (DTE)); 34 | if (!string.IsNullOrEmpty(dte.Solution.FullName)) 35 | { 36 | var solutionDirectory = Path.GetDirectoryName(dte.Solution.FullName); 37 | taskFileProcessor.ProcessTaskFile(solutionDirectory); 38 | } 39 | } 40 | catch (Exception exception) 41 | { 42 | exceptionDialog.HandleException(exception); 43 | } 44 | return VSConstants.S_OK; 45 | } 46 | 47 | public int OnQueryCloseSolution(object pUnkReserved, ref int pfCancel) 48 | { 49 | return VSConstants.S_OK; 50 | } 51 | 52 | public int OnBeforeCloseSolution(object pUnkReserved) 53 | { 54 | return VSConstants.S_OK; 55 | } 56 | 57 | public int OnAfterCloseSolution(object pUnkReserved) 58 | { 59 | msBuildKiller.Kill(); 60 | return VSConstants.S_OK; 61 | } 62 | 63 | public int OnAfterOpenProject(IVsHierarchy pHierarchy, int fAdded) 64 | { 65 | return VSConstants.S_OK; 66 | } 67 | 68 | public int OnQueryCloseProject(IVsHierarchy pHierarchy, int fRemoving, ref int pfCancel) 69 | { 70 | return VSConstants.S_OK; 71 | } 72 | 73 | public int OnBeforeCloseProject(IVsHierarchy pHierarchy, int fRemoved) 74 | { 75 | return VSConstants.S_OK; 76 | } 77 | 78 | public int OnAfterLoadProject(IVsHierarchy pStubHierarchy, IVsHierarchy pRealHierarchy) 79 | { 80 | return VSConstants.S_OK; 81 | } 82 | 83 | public int OnQueryUnloadProject(IVsHierarchy pRealHierarchy, ref int pfCancel) 84 | { 85 | return VSConstants.S_OK; 86 | } 87 | 88 | public int OnBeforeUnloadProject(IVsHierarchy pRealHierarchy, IVsHierarchy pStubHierarchy) 89 | { 90 | return VSConstants.S_OK; 91 | } 92 | 93 | } -------------------------------------------------------------------------------- /FodyCommon.Tests/FodyCommon.Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {C66C8111-BE64-4899-BD7C-688A9ED3A62F} 8 | Library 9 | Properties 10 | FodyCommon.Tests 11 | FodyCommon.Tests 12 | 512 13 | 12.0.0 14 | 2.0 15 | 16 | 17 | True 18 | full 19 | False 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | pdbonly 27 | True 28 | bin\Release\ 29 | TRACE 30 | prompt 31 | 4 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | ..\packages\NUnit.2.6.2\lib\nunit.framework.dll 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | {E839A346-8804-4EAC-B635-19D7A911460E} 51 | FodyCommon 52 | 53 | 54 | {64880F43-E6C1-428E-B00A-E0374697B5CF} 55 | Fody 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /SampleTask.Fody/SampleTask.Fody.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | AnyCPU 6 | 8.0.30703 7 | 2.0 8 | {2C10CBD1-5913-46D5-B705-0F3B46E68DD1} 9 | Library 10 | Properties 11 | Sample.Fody 12 | Sample.Fody 13 | 512 14 | 15 | 16 | True 17 | full 18 | False 19 | bin\Debug\ 20 | DEBUG;TRACE 21 | prompt 22 | 4 23 | 24 | 25 | pdbonly 26 | True 27 | bin\Release\ 28 | TRACE 29 | prompt 30 | 4 31 | 32 | 33 | 34 | ..\Lib\Cecil\Mono.Cecil.dll 35 | 36 | 37 | ..\Lib\Cecil\Mono.Cecil.Mdb.dll 38 | 39 | 40 | ..\Lib\Cecil\Mono.Cecil.Pdb.dll 41 | 42 | 43 | ..\Lib\Cecil\Mono.Cecil.Rocks.dll 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /ChocolateyNuGet/ChocolateyNuget.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | AnyCPU 6 | {63786CE5-D899-43DF-AD4E-C2CA3BAC3FC2} 7 | 12.0.0 8 | 2.0 9 | Exe 10 | ChocolateyNuget 11 | 12 | 13 | Debug 14 | bin\Debug 15 | none 16 | 4 17 | False 18 | 19 | 20 | Release 21 | bin\Release 22 | none 23 | 4 24 | False 25 | 26 | 27 | 28 | Designer 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | false 48 | FodyVSPackage 49 | {2356DD30-B9AC-48ED-A0A1-103382A9CFC3} 50 | 51 | 52 | false 53 | Fody 54 | {64880F43-E6C1-428E-B00A-E0374697B5CF} 55 | 56 | 57 | -------------------------------------------------------------------------------- /FodyCommon/FodyCommon.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {E839A346-8804-4EAC-B635-19D7A911460E} 8 | Library 9 | Properties 10 | FodyCommon 11 | FodyCommon 12 | 512 13 | 12.0.0 14 | 2.0 15 | 16 | 17 | True 18 | full 19 | False 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | pdbonly 27 | True 28 | bin\Release\ 29 | TRACE 30 | prompt 31 | 4 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /Fody/BuildLogger.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | using Microsoft.Build.Framework; 4 | 5 | public class BuildLogger : MarshalByRefObject, ILogger 6 | { 7 | public IBuildEngine BuildEngine { get; set; } 8 | public MessageImportance MessageImportance { get; set; } 9 | public bool ErrorOccurred; 10 | string currentWeaverName; 11 | 12 | StringBuilder stringBuilder; 13 | 14 | //TODO: remove and move to interface 15 | public BuildLogger() 16 | { 17 | } 18 | 19 | public BuildLogger(string messageImportance) 20 | { 21 | stringBuilder = new StringBuilder(); 22 | if (string.IsNullOrWhiteSpace(messageImportance)) 23 | { 24 | MessageImportance = MessageImportance.Low; 25 | } 26 | else 27 | { 28 | MessageImportance messageImportanceEnum; 29 | if (!Enum.TryParse(messageImportance, out messageImportanceEnum)) 30 | { 31 | throw new WeavingException(string.Format("Invalid MessageImportance in config. Should be 'Low', 'Normal' or 'High' but was '{0}'.", messageImportance)); 32 | } 33 | MessageImportance = messageImportanceEnum; 34 | } 35 | } 36 | 37 | public void LogWarning(string message) 38 | { 39 | LogWarning(message, null, 0, 0, 0, 0); 40 | } 41 | 42 | public void LogWarning(string message, string file, int lineNumber, int columnNumber, int endLineNumber, int endColumnNumber) 43 | { 44 | stringBuilder.AppendLine(" Warning: " + message); 45 | BuildEngine.LogWarningEvent(new BuildWarningEventArgs("", "", file, lineNumber, columnNumber, endLineNumber, endColumnNumber, PrependMessage(message), "", "Fody")); 46 | } 47 | 48 | public void SetCurrentWeaverName(string weaverName) 49 | { 50 | currentWeaverName = weaverName; 51 | } 52 | 53 | public void ClearWeaverName() 54 | { 55 | currentWeaverName = null; 56 | } 57 | 58 | public void LogInfo(string message) 59 | { 60 | stringBuilder.AppendLine(" " + message); 61 | } 62 | 63 | public void LogError(string message) 64 | { 65 | LogError(message, null, 0, 0, 0, 0); 66 | } 67 | 68 | public void LogError(string message, string file, int lineNumber, int columnNumber, int endLineNumber, int endColumnNumber) 69 | { 70 | ErrorOccurred = true; 71 | stringBuilder.AppendLine(" Error: " + message); 72 | BuildEngine.LogErrorEvent(new BuildErrorEventArgs("", "", file, lineNumber, columnNumber, endLineNumber, endColumnNumber,PrependMessage( message), "", "Fody")); 73 | } 74 | 75 | string PrependMessage(string message) 76 | { 77 | if (currentWeaverName == null) 78 | { 79 | return "Fody: " + message; 80 | } 81 | 82 | return string.Format("Fody/{0}: {1}", currentWeaverName, message); 83 | } 84 | 85 | 86 | public void Flush() 87 | { 88 | var message = stringBuilder.ToString(); 89 | //message = message.Substring(0, message.Length - 2); 90 | BuildEngine.LogMessageEvent(new BuildMessageEventArgs(message, "", "Fody", MessageImportance)); 91 | } 92 | 93 | 94 | } -------------------------------------------------------------------------------- /Fody.Tests/NugetConfigReaderTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using NUnit.Framework; 4 | 5 | [TestFixture] 6 | public class NugetConfigReaderTest 7 | { 8 | [Test] 9 | public void WithNugetConfig() 10 | { 11 | var solutionDir = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, "../../NugetPackagePathFinder/FakeSolutionWithNugetConfig")); 12 | var packagesPathFromConfig = NugetConfigReader.GetPackagesPathFromConfig(solutionDir); 13 | Assert.IsTrue(packagesPathFromConfig.EndsWith("FromNugetConfig")); 14 | } 15 | 16 | [Test] 17 | public void FakeSolutionWithNesetdNugetConfig() 18 | { 19 | var solutionDir = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, "../../NugetPackagePathFinder/FakeSolutionWithNesetdNugetConfig")); 20 | var packagesPathFromConfig = NugetConfigReader.GetPackagesPathFromConfig(solutionDir); 21 | Assert.IsTrue(packagesPathFromConfig.EndsWith("FromNugetConfig")); 22 | } 23 | [Test] 24 | public void WithNugetConfigInTree() 25 | { 26 | var solutionDir = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, "../../NugetPackagePathFinder/FakeSolutionWithNugetConfig/Foo")); 27 | var packagesPathFromConfig = NugetConfigReader.GetPackagesPathFromConfig(solutionDir); 28 | Assert.IsTrue(packagesPathFromConfig.EndsWith("FromNugetConfig")); 29 | } 30 | 31 | [Test] 32 | public void WithNoNugetConfigInTree() 33 | { 34 | var solutionDir = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, "../../NugetPackagePathFinder/FakeSolutionNoNugetConfig")); 35 | var packagesPathFromConfig = NugetConfigReader.GetPackagesPathFromConfig(solutionDir); 36 | Assert.IsNull(packagesPathFromConfig); 37 | } 38 | 39 | [Test] 40 | public void NugetConfigWithRepoNode() 41 | { 42 | var configPath = Path.Combine(Environment.CurrentDirectory, "NugetConfigWithRepoNode.txt"); 43 | var packagesPathFromConfig = NugetConfigReader.GetPackagePath(configPath); 44 | Assert.AreEqual(Path.Combine(Environment.CurrentDirectory,"repositoryPathValue"), packagesPathFromConfig); 45 | } 46 | 47 | [Test] 48 | public void NugetConfigWithKeyNodeEmpty() 49 | { 50 | var configPath = Path.Combine(Environment.CurrentDirectory, "NugetConfigWithKeyNodeEmpty.txt"); 51 | var packagesPathFromConfig = NugetConfigReader.GetPackagePath(configPath); 52 | Assert.IsNull(packagesPathFromConfig); 53 | } 54 | 55 | [Test] 56 | public void NugetConfigWithRepoNodeEmpty() 57 | { 58 | var configPath = Path.Combine(Environment.CurrentDirectory, "NugetConfigWithRepoNodeEmpty.txt"); 59 | var packagesPathFromConfig = NugetConfigReader.GetPackagePath(configPath); 60 | Assert.IsNull(packagesPathFromConfig); 61 | } 62 | 63 | [Test] 64 | public void NugetConfigWithKeyNode() 65 | { 66 | var configPath = Path.Combine(Environment.CurrentDirectory, "NugetConfigWithKeyNode.txt"); 67 | var packagesPathFromConfig = NugetConfigReader.GetPackagePath(configPath); 68 | Assert.AreEqual(Path.Combine(Environment.CurrentDirectory,"repositoryPathValue"), packagesPathFromConfig); 69 | } 70 | 71 | } -------------------------------------------------------------------------------- /Integration/Tests/Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | AnyCPU 6 | 8.0.30703 7 | 2.0 8 | {9C8338D4-3F27-4FA5-97A0-6039FDB07724} 9 | Library 10 | Properties 11 | Tests 12 | Tests 13 | v4.0 14 | 512 15 | High 16 | 17 | 18 | true 19 | full 20 | false 21 | bin\Debug\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | 26 | 27 | pdbonly 28 | true 29 | bin\Release\ 30 | TRACE 31 | prompt 32 | 4 33 | 34 | 35 | 36 | False 37 | ..\packages\NUnit.2.6.0.12054\lib\nunit.framework.dll 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | Designer 50 | 51 | 52 | 53 | 54 | {7DDD6A9E-7D35-4D5B-8B60-D9D32F3D521A} 55 | WithNugetAndInSolutionWeavers 56 | 57 | 58 | {4744FEC7-AE13-4A20-81C6-BBB837C19B5F} 59 | WithNugetWeavers 60 | 61 | 62 | {4D1BF1C8-5C19-4A95-BEFF-6F8D67FF7B87} 63 | WithOnlyInSolutionWeaver 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /Integration/Weavers/Weavers.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | AnyCPU 6 | 8.0.30703 7 | 2.0 8 | {3F4C62F3-F582-452F-B455-0CD5C89D96CF} 9 | Library 10 | Properties 11 | Weavers 12 | Weavers 13 | v4.0 14 | 512 15 | 16 | 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | pdbonly 27 | true 28 | bin\Release\ 29 | TRACE 30 | prompt 31 | 4 32 | 33 | 34 | 35 | False 36 | ..\packages\Mono.Cecil.0.9.5.3\lib\net40\Mono.Cecil.dll 37 | 38 | 39 | False 40 | ..\packages\Mono.Cecil.0.9.5.3\lib\net40\Mono.Cecil.Mdb.dll 41 | 42 | 43 | False 44 | ..\packages\Mono.Cecil.0.9.5.3\lib\net40\Mono.Cecil.Pdb.dll 45 | 46 | 47 | False 48 | ..\packages\Mono.Cecil.0.9.5.3\lib\net40\Mono.Cecil.Rocks.dll 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | Designer 65 | 66 | 67 | 68 | 69 | --------------------------------------------------------------------------------