Fody.targets 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <Project>
  2. <PropertyGroup>
  3. <ProjectWeaverXml Condition="$(ProjectWeaverXml) == ''">$(ProjectDir)FodyWeavers.xml</ProjectWeaverXml>
  4. <FodyPath Condition="$(FodyPath) == ''">$(MSBuildThisFileDirectory)..\</FodyPath>
  5. <FodyAssemblyDirectory Condition="$(MSBuildRuntimeType) == 'Core'">$(FodyPath)netstandardtask</FodyAssemblyDirectory>
  6. <FodyAssemblyDirectory Condition="$(MSBuildRuntimeType) != 'Core'">$(FodyPath)netclassictask</FodyAssemblyDirectory>
  7. <FodyAssembly Condition="$(FodyAssembly) == ''">$(FodyAssemblyDirectory)\Fody.dll</FodyAssembly>
  8. <DefaultItemExcludes>$(DefaultItemExcludes);FodyWeavers.xsd</DefaultItemExcludes>
  9. <FodyGenerateXsd Condition="$(FodyGenerateXsd) == ''">true</FodyGenerateXsd>
  10. <MsBuildMajorVersion>15</MsBuildMajorVersion>
  11. <MsBuildMajorVersion Condition="'$(MSBuildVersion)' != ''">$([System.Version]::Parse($(MSBuildVersion)).Major)</MsBuildMajorVersion>
  12. </PropertyGroup>
  13. <ItemGroup Condition="Exists($(ProjectWeaverXml))">
  14. <UpToDateCheckInput Include="$(ProjectWeaverXml)" />
  15. <CustomAdditionalCompileInputs Include="$(ProjectWeaverXml)" />
  16. </ItemGroup>
  17. <!-- Support for NCrunch -->
  18. <ItemGroup Condition="'$(NCrunch)' == '1' and '$(TargetFramework)' == '' and '$(TargetFrameworks)' == ''">
  19. <None Include="$(FodyAssemblyDirectory)\*.*" />
  20. <None Include="@(WeaverFiles)" />
  21. </ItemGroup>
  22. <UsingTask TaskName="Fody.WeavingTask" AssemblyFile="$(FodyAssembly)" />
  23. <UsingTask TaskName="Fody.UpdateCopyLocalTask" AssemblyFile="$(FodyAssembly)" />
  24. <UsingTask TaskName="Fody.VerifyTask" AssemblyFile="$(FodyAssembly)" />
  25. <Target
  26. Name="FodyTarget"
  27. AfterTargets="AfterCompile"
  28. Condition="Exists(@(IntermediateAssembly)) And ($(DesignTimeBuild) != true Or $(BuildingForLiveUnitTesting) == true) And $(DisableFody) != true"
  29. DependsOnTargets="$(FodyDependsOnTargets)"
  30. Inputs="@(IntermediateAssembly);$(ProjectWeaverXml)"
  31. Outputs="$(IntermediateOutputPath)$(MSBuildProjectFile).Fody.CopyLocal.cache;$(IntermediateOutputPath)$(MSBuildProjectFile).Fody.RuntimeCopyLocal.cache">
  32. <Error Condition="($(MsBuildMajorVersion) &lt; 16)"
  33. Text="Fody is only supported on MSBuild 16 and above. Current version: $(MsBuildMajorVersion)." />
  34. <Fody.WeavingTask
  35. AssemblyFile="@(IntermediateAssembly)"
  36. IntermediateDirectory="$(ProjectDir)$(IntermediateOutputPath)"
  37. KeyOriginatorFile="$(KeyOriginatorFile)"
  38. AssemblyOriginatorKeyFile="$(AssemblyOriginatorKeyFile)"
  39. ProjectDirectory="$(MSBuildProjectDirectory)"
  40. ProjectFile="$(MSBuildProjectFullPath)"
  41. SolutionDirectory="$(SolutionDir)"
  42. References="@(ReferencePath)"
  43. SignAssembly="$(SignAssembly)"
  44. DelaySign="$(DelaySign)"
  45. ReferenceCopyLocalFiles="@(ReferenceCopyLocalPaths)"
  46. RuntimeCopyLocalFiles="@(RuntimeCopyLocalItems)"
  47. DefineConstants="$(DefineConstants)"
  48. DocumentationFile="@(DocFileItem->'%(FullPath)')"
  49. WeaverFiles="@(WeaverFiles)"
  50. WeaverConfiguration="$(WeaverConfiguration)"
  51. PackageReferences="@(PackageReference)"
  52. NCrunchOriginalSolutionDirectory="$(NCrunchOriginalSolutionDir)"
  53. IntermediateCopyLocalFilesCache="$(IntermediateOutputPath)$(MSBuildProjectFile).Fody.CopyLocal.cache"
  54. RuntimeCopyLocalFilesCache="$(IntermediateOutputPath)$(MSBuildProjectFile).Fody.RuntimeCopyLocal.cache"
  55. GenerateXsd="$(FodyGenerateXsd)"
  56. >
  57. <Output
  58. TaskParameter="ExecutedWeavers"
  59. PropertyName="FodyExecutedWeavers" />
  60. </Fody.WeavingTask>
  61. <ItemGroup>
  62. <FileWrites Include="$(IntermediateOutputPath)$(MSBuildProjectFile).Fody.CopyLocal.cache" />
  63. <FileWrites Include="$(IntermediateOutputPath)$(MSBuildProjectFile).Fody.RuntimeCopyLocal.cache" />
  64. </ItemGroup>
  65. </Target>
  66. <Target
  67. Name="FodyUpdateReferenceCopyLocalFilesTarget"
  68. AfterTargets="FodyTarget"
  69. >
  70. <Fody.UpdateCopyLocalTask
  71. CopyLocalFiles="@(ReferenceCopyLocalPaths)"
  72. IntermediateCopyLocalFilesCache="$(IntermediateOutputPath)$(MSBuildProjectFile).Fody.CopyLocal.cache"
  73. >
  74. <Output
  75. TaskParameter="UpdatedCopyLocalFiles"
  76. ItemName="FodyUpdatedReferenceCopyLocalPaths" />
  77. </Fody.UpdateCopyLocalTask>
  78. <ItemGroup>
  79. <FodyRemovedReferenceCopyLocalPaths Include="@(ReferenceCopyLocalPaths)" />
  80. <FodyRemovedReferenceCopyLocalPaths Remove="@(FodyUpdatedReferenceCopyLocalPaths)" />
  81. <ReferenceCopyLocalPaths Remove="@(ReferenceCopyLocalPaths)" />
  82. <ReferenceCopyLocalPaths Include="@(FodyUpdatedReferenceCopyLocalPaths)" />
  83. </ItemGroup>
  84. </Target>
  85. <Target
  86. Name="FodyUpdateRuntimeCopyLocalItemsTarget"
  87. AfterTargets="FodyTarget"
  88. >
  89. <Fody.UpdateCopyLocalTask
  90. CopyLocalFiles="@(RuntimeCopyLocalItems)"
  91. IntermediateCopyLocalFilesCache="$(IntermediateOutputPath)$(MSBuildProjectFile).Fody.RuntimeCopyLocal.cache"
  92. >
  93. <Output
  94. TaskParameter="UpdatedCopyLocalFiles"
  95. ItemName="FodyUpdatedRuntimeCopyLocalItems" />
  96. </Fody.UpdateCopyLocalTask>
  97. <ItemGroup>
  98. <FodyRemovedRuntimeCopyLocalItems Include="@(RuntimeCopyLocalItems)" />
  99. <FodyRemovedRuntimeCopyLocalItems Remove="@(FodyUpdatedRuntimeCopyLocalItems)" />
  100. <RuntimeCopyLocalItems Remove="@(RuntimeCopyLocalItems)" />
  101. <RuntimeCopyLocalItems Include="@(FodyUpdatedRuntimeCopyLocalItems)" />
  102. </ItemGroup>
  103. </Target>
  104. <Target
  105. Name="FodyVerifyTarget"
  106. AfterTargets="AfterBuild"
  107. Condition="'$(NCrunch)' != '1' And $(FodyExecutedWeavers) != '' And $(DisableFody) != true"
  108. DependsOnTargets="$(FodyVerifyDependsOnTargets)">
  109. <Fody.VerifyTask
  110. ProjectDirectory="$(MSBuildProjectDirectory)"
  111. TargetPath="$(TargetPath)"
  112. SolutionDirectory="$(SolutionDir)"
  113. WeaverConfiguration="$(WeaverConfiguration)"
  114. DefineConstants="$(DefineConstants)"
  115. NCrunchOriginalSolutionDirectory="$(NCrunchOriginalSolutionDir)"
  116. />
  117. </Target>
  118. </Project>