问题描述
我正在使用目标文件在运行时生成一些文件,并将它们从中间目录(obj)复制到bin。
我的环境是.Net 5和相应的MSBUILD版本。
通常我的.targets文件可以工作,但是我有一个问题:
当文件在中间目录中生成时,它们保存在obj/x64/Debug/...FileName.fx
之类的路径中,而整个路径正好复制到bin文件夹中的输出中。
例如,我的原始文件位于Effects/BasicEffect.fx
中,但我想将此结构保留在输出中,但是它将复制到obj/x64/Debug/Effects/BasicEffect.fxo
中,最终路径为:bin/x64/Debug/obj/x64/Debug/Effects/BasicEffect.fxo
。这就是我要修复的
这是我的目标文件:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<AvailableItemName Include="Effect"/>
<!--<AvailableItemName Include="Font"/>-->
</ItemGroup>
<!-- In Project A -->
<UsingTask Architecture="*" TaskName="EffectCompilerTask" AssemblyFile="$(SolutionDir)CompilerTask\bin\Debug\net5.0\CompilerTask.dll"/>
<UsingTask Architecture="*" TaskName="CompilerDependencyTask" AssemblyFile="$(SolutionDir)CompilerTask\bin\Debug\net5.0\CompilerTask.dll"/>
<!-- 1st PART : When Project A is built,It will generate effectively the files -->
<!-- Plugs all dependency listing in AssignTargetPathsDependsOn - in order to support generated output to be copied as part of the build -->
<PropertyGroup >
<BuildDependsOn>
EngineCompileTarget;
$(BuildDependsOn);
</BuildDependsOn>
<IsBuildInDebug>true</IsBuildInDebug>
<!--By default turn-on debugging on fx files when compiling in debug (no optimize)-->
<EngineEffectDebugOption Condition="'$(EngineEffectDebugOption)' == ''">$(IsBuildInDebug)</EngineEffectDebugOption>
<EffectDynamicCompilingOption Condition="'$(EffectDynamicCompilingOption)' == ''">$(IsBuildInDebug)</EffectDynamicCompilingOption>
<GenerateCsFileFromEffect>false</GenerateCsFileFromEffect>
<GenerateBinaryFromEffect>true</GenerateBinaryFromEffect>
<GenerateCsFileFromFont>false</GenerateCsFileFromFont>
<GenerateBinaryFromFont>true</GenerateBinaryFromFont>
<CompileFontBitmaps>false</CompileFontBitmaps>
</PropertyGroup>
<Target Name="EngineContentAndCompileTarget" BeforeTargets="Build">
<CompilerDependencyTask
ProjectDirectory="$(ProjectDir)"
IntermediateDirectory="$(IntermediateOutputPath)"
Files="@(Effect)"
>
<Output ItemName="EngineContent" TaskParameter="ContentFiles" />
</CompilerDependencyTask>
<ItemGroup>
<!--List Of fx compiled file-->
<Content Include="@(EngineContent)" KeepMetadata="CopyToOutputDirectory"/>
</ItemGroup>
</Target>
<!-- Target used to calculate dependency output -->
<Target Name="EngineCompileTarget" BeforeTargets="Build">
<EffectCompilerTask
Files="@(Effect)"
ProjectDirectory="$(ProjectDir)"
IntermediateDirectory="$(IntermediateOutputPath)"
>
</EffectCompilerTask>
<Message Text="Hello from EngineCompileTarget" Importance="High"></Message>
<Message Text="EngineCompileTarget @(Content)" Importance="High"></Message>
</Target>
</Project>
这是我的Directory.buid.targets
文件,我将其添加到正在构建解决方案的项目中。
这是此文件的内容:
<Project>
<PropertyGroup>
<AssignTargetPathsDependsOn>
$(AssignTargetPathsDependsOn);
EngineContentAndCompileTarget;
</AssignTargetPathsDependsOn>
</PropertyGroup>
</Project>
有人可以指出我在这里所缺少的内容,以便在保存原始文件结构的情况下将生成的文件正确地复制到输出中吗?