/
AspectInjector.targets
99 lines (86 loc) · 4.43 KB
/
AspectInjector.targets
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<_InjectAspectsDependsOn>
_ASI_CheckAssemblyChanged;
_ASI_InjectAspectsCore;
_ASI_ResignAssembly;
_ASI_TouchTimestampFile
</_InjectAspectsDependsOn>
</PropertyGroup>
<PropertyGroup>
<_ASI_Loaded>true</_ASI_Loaded>
<_ASI_Location Condition="'$(_ASI_Location)' == ''">$(MSBuildThisFileDirectory)../../build/_bin/</_ASI_Location>
<_ASI_Options Condition="'$(Optimize)' == 'true'">$(_ASI_Options) -o</_ASI_Options>
</PropertyGroup>
<PropertyGroup>
<AspectInjectorEnabled Condition="'$(AspectInjectorEnabled)' == ''">true</AspectInjectorEnabled>
</PropertyGroup>
<PropertyGroup>
<_ASI_RefsFileExt>._asi_refs</_ASI_RefsFileExt>
</PropertyGroup>
<Target Name="InjectAspects" AfterTargets="CoreCompile" Condition="'$(AspectInjectorEnabled)' == 'true'" DependsOnTargets="$(_InjectAspectsDependsOn)"/>
<Target Name="_ASI_InjectAspectsCore" Condition="'$(_InjectionNeeded)' == 'true'">
<PropertyGroup>
<ProcessCmd>dotnet "$(_ASI_Location)AspectInjector.dll" $(_ASI_Options) -rf "%(IntermediateAssembly.FullPath)$(_ASI_RefsFileExt)" "@(IntermediateAssembly->'%(FullPath)')"</ProcessCmd>
</PropertyGroup>
<Exec Command="$(ProcessCmd)" WorkingDirectory="$(MSBuildThisFileDirectory)" EchoOff="true" IgnoreExitCode="true">
<Output TaskParameter="ExitCode" PropertyName="_AspectExitCode" />
</Exec>
<Error Text="Aspect Injector processing has failed. See other errors." Condition="'$(_AspectExitCode)' != '0'" Code="AI_FAIL" File="AspectInjector"/>
</Target>
<Target Name="_ASI_ResignAssembly" Condition="'$(SignAssembly)' == 'true' AND '$(DelaySign)' != 'true' AND '$(_InjectionNeeded)' == 'true' " DependsOnTargets="GetSnToolForUnix;GetSnToolForWindows">
<PropertyGroup>
<_SignCommand Condition="'$(KeyContainerName)' != ''">"$(SnTool)" -Rc "$(ProjectDir)$(IntermediateOutputPath)$(TargetFileName)" $(KeyContainerName)</_SignCommand>
<_SignCommand Condition="'$(KeyContainerName)' == '' AND '$(KeyOriginatorFile)' != ''">"$(SnTool)" -R "$(ProjectDir)$(IntermediateOutputPath)$(TargetFileName)" $(KeyOriginatorFile)</_SignCommand>
</PropertyGroup>
<Exec Command="$(_SignCommand)" Condition="'$(_SignCommand)' != ''" EchoOff="true" IgnoreExitCode="true">
<Output TaskParameter="ExitCode" PropertyName="_SignExitCode" />
</Exec>
<Error Text="Aspect Injector cannot re-sing assembly. Try rebuid solution." Condition="'$(_SignExitCode)' != '0'" Code="AI_ERR0" File="AspectInjector"/>
</Target>
<Target Name="_ASI_TouchTimestampFile" Condition="'$(_InjectionNeeded)' == 'true'">
<Touch Files="%(IntermediateAssembly.FullPath)$(_ASI_RefsFileExt)" AlwaysCreate="true" Time="%(IntermediateAssembly.ModifiedTime)"/>
<PropertyGroup>
<_InjectionNeeded>false</_InjectionNeeded>
</PropertyGroup>
</Target>
<Target Name="_ASI_CheckAssemblyChanged">
<ItemGroup>
<_TimeStampFiles Include="%(IntermediateAssembly.FullPath)$(_ASI_RefsFileExt)" />
</ItemGroup>
<PropertyGroup>
<_TSOld>%(_TimeStampFiles.ModifiedTime)</_TSOld>
<_TSNew>%(IntermediateAssembly.ModifiedTime)</_TSNew>
</PropertyGroup>
<PropertyGroup>
<_InjectionNeeded Condition="'$(_TSOld)' != '$(_TSNew)' AND '$(_TSNew)' != '' ">true</_InjectionNeeded>
</PropertyGroup>
<WriteLinesToFile Condition="'$(_InjectionNeeded)' == 'true'"
File="%(IntermediateAssembly.FullPath)$(_ASI_RefsFileExt)"
Lines="@(ReferencePath)"
Overwrite="true"
Encoding="Unicode"/>
<Message Text="Assembly requires injection." Condition="'$(_InjectionNeeded)' == 'true'"/>
</Target>
<Target Name="GetSnToolForUnix" Condition=" '$(OS)' == 'Unix' ">
<PropertyGroup>
<SnTool>sn</SnTool>
</PropertyGroup>
<Message Text="SnTool found: $(SnTool)"/>
</Target>
<Target Name="GetSnToolForWindows" Condition=" '$(OS)' != 'Unix' ">
<GetFrameworkSdkPath>
<Output TaskParameter="Path" PropertyName="WindowsSdkPath" />
</GetFrameworkSdkPath>
<ItemGroup>
<SnTools Include="$(WindowsSdkPath)**\sn.exe" />
</ItemGroup>
<PropertyGroup>
<SnToolsRaw>@(SnTools)</SnToolsRaw>
</PropertyGroup>
<PropertyGroup>
<SnTool>$(SnToolsRaw.Split(';')[0])</SnTool>
</PropertyGroup>
<Message Text="SnTool found: $(SnTool)"/>
</Target>
</Project>