Permalink
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
110 lines (101 sloc) 6.1 KB
<Project>
<!--第二阶段,创建 SourceFusion 需要的文件夹-->
<Target Name="_SourceFusionEnsureToolPath" BeforeTargets="SourceFusionGenerateCode">
<PropertyGroup Condition=" $(IsInDemoToolDebugMode) == 'True' ">
<TransformCodeToolPath>$(MSBuildThisFileDirectory)..\..\bin\$(Configuration)\net47\codet.exe</TransformCodeToolPath>
</PropertyGroup>
<PropertyGroup Condition=" $(IsInDemoToolDebugMode) != 'True' ">
<TransformCodeToolPath>$(MSBuildThisFileDirectory)..\tools\net47\codet.exe</TransformCodeToolPath>
</PropertyGroup>
<PropertyGroup Condition=" $(UseDotNetCore) == 'True' ">
<TransformCodeToolPath>dotnet $(MSBuildThisFileDirectory)..\tools\netcoreapp2.1\codet.dll</TransformCodeToolPath>
</PropertyGroup>
</Target>
<!--第一阶段,创建 SourceFusion 需要的文件夹-->
<Target Name="_SourceFusionCreateDirectories" BeforeTargets="_SourceFusionWriteArgs">
<PropertyGroup>
<_DefaultSourceFusionWorkingFolder Condition="'$(_DefaultSourceFusionWorkingFolder)' == ''">obj\$(Configuration)\</_DefaultSourceFusionWorkingFolder>
<SourceFusionWorkingFolder Condition="'$(SourceFusionWorkingFolder)' == ''">$(_DefaultSourceFusionWorkingFolder)</SourceFusionWorkingFolder>
<SourceFusionToolsFolder>$(SourceFusionWorkingFolder)SourceFusion.Tools\</SourceFusionToolsFolder>
<SourceFusionGeneratedCodeFolder>$(SourceFusionWorkingFolder)SourceFusion.GeneratedCodes\</SourceFusionGeneratedCodeFolder>
</PropertyGroup>
<ItemGroup>
<SourceFusionDirectory Include="$(SourceFusionWorkingFolder)" />
<SourceFusionDirectory Include="$(SourceFusionToolsFolder)" />
<SourceFusionDirectory Include="$(SourceFusionGeneratedCodeFolder)" />
</ItemGroup>
<MakeDir Directories="@(SourceFusionDirectory)" ContinueOnError="false" />
</Target>
<!--第二阶段,写入 SourceFusion 需要的命令行参数-->
<Target Name="_SourceFusionWriteArgs" BeforeTargets="SourceFusionGenerateCode">
<PropertyGroup>
<SourceFusionProjectPropertyFile Condition=" '$(SourceFusionProjectPropertyFile)' == '' ">$(SourceFusionToolsFolder)CommandArgs.txt</SourceFusionProjectPropertyFile>
</PropertyGroup>
<ItemGroup>
<!--这里正在按格式编写配置文件,配置文件尚未开源,所以暂时没有名字。-->
<SourceFusionCommandArgLine Include=">" />
<SourceFusionCommandArgLine Include="RootNamespace" />
<SourceFusionCommandArgLine Include="$(RootNamespace)" />
<SourceFusionCommandArgLine Include=">" />
<SourceFusionCommandArgLine Include="Compile" />
<SourceFusionCommandArgLine Include="@(Compile)" />
<SourceFusionCommandArgLine Include=">" />
<SourceFusionCommandArgLine Include="PrecompileFilter" />
<SourceFusionCommandArgLine Include="@(PrecompileFilter)" />
<SourceFusionCommandArgLine Include=">" />
<SourceFusionCommandArgLine Include="ReferencePath" />
<SourceFusionCommandArgLine Include="@(ReferencePath)" />
<SourceFusionCommandArgLine Include=">" />
</ItemGroup>
<WriteLinesToFile File="$(SourceFusionProjectPropertyFile)" Lines="@(SourceFusionCommandArgLine)" Overwrite="True" />
</Target>
<!--第二阶段,进行重新编译测试-->
<Target Name="_SourceFusionRebuildingTest" BeforeTargets="SourceFusionGenerateCode"
Inputs="$(MSBuildProjectFullPath)" Outputs="$(SourceFusionToolsFolder)RebuildingTest.txt">
<ItemGroup>
<RebuildingTestLine Include="true" />
</ItemGroup>
<CallTarget Targets="_SourceFusionRebuildingTestInitialize" />
<WriteLinesToFile File="$(SourceFusionToolsFolder)RebuildingTest.txt" Lines="@(RebuildingTestLine)" Overwrite="True" />
</Target>
<Target Name="_SourceFusionRebuildingTestInitialize">
<PropertyGroup>
<SourceFusionRebuildRequired>true</SourceFusionRebuildRequired>
</PropertyGroup>
</Target>
<!--第三阶段,执行 SourceFusion-->
<Target Name="SourceFusionGenerateCode" BeforeTargets="CoreCompile;ResolveAssemblyReference">
<PropertyGroup>
<SourceFusionRebuildRequired Condition="'$(SourceFusionRebuildRequired)' == ''">false</SourceFusionRebuildRequired>
</PropertyGroup>
<Exec ConsoleToMSBuild="True"
Command="&quot;$(TransformCodeToolPath)&quot; &quot;$(MSBuildProjectDirectory)&quot; -t $(SourceFusionToolsFolder) -c $(SourceFusionGeneratedCodeFolder) -p &quot;$(SourceFusionProjectPropertyFile)&quot; -s $(DefineConstants) --rebuild $(SourceFusionRebuildRequired)">
<Output TaskParameter="ConsoleOutput" PropertyName="_OutputOfSourceFusionGenerateCode" />
<Output TaskParameter="ExitCode" PropertyName="_ExitCodeOfSourceFusion" />
</Exec>
</Target>
<!--第四阶段,使用 SourceFusion 生成的新源码-->
<Target Name="_IncludeSourceFusionGeneratedCode" Condition="$(_ExitCodeOfSourceFusion) == '0' " AfterTargets="SourceFusionGenerateCode">
<CreateItem Include="$(_OutputOfSourceFusionGenerateCode)">
<Output TaskParameter="Include" ItemName="_ExcludedCompileFile" />
</CreateItem>
<ItemGroup>
<Compile Include="$(SourceFusionGeneratedCodeFolder)\*.cs" />
<Compile Remove="@(_ExcludedCompileFile)" />
</ItemGroup>
<Message Text="编译时排除的文件:@(_ExcludedCompileFile)" />
</Target>
<PropertyGroup>
<CleanDependsOn>$(CleanDependsOn);_SourceFusionClean</CleanDependsOn>
</PropertyGroup>
<!--清理 SourceFusion 计算所得的文件-->
<Target Name="_SourceFusionClean">
<PropertyGroup>
<_DefaultSourceFusionWorkingFolder Condition="'$(_DefaultSourceFusionWorkingFolder)' == ''">obj\$(Configuration)\</_DefaultSourceFusionWorkingFolder>
<SourceFusionWorkingFolder Condition="'$(SourceFusionWorkingFolder)' == ''">$(_DefaultSourceFusionWorkingFolder)</SourceFusionWorkingFolder>
<SourceFusionToolsFolder>$(SourceFusionWorkingFolder)SourceFusion.Tools\</SourceFusionToolsFolder>
<SourceFusionGeneratedCodeFolder>$(SourceFusionWorkingFolder)SourceFusion.GeneratedCodes\</SourceFusionGeneratedCodeFolder>
</PropertyGroup>
<RemoveDir Directories="$(SourceFusionToolsFolder);$(SourceFusionGeneratedCodeFolder)" />
</Target>
</Project>