简体   繁体   English

如何将自定义编译文件(在 Target/Exec 中)添加为.csproj 中的资源?

[英]How to add custom compiled file (in Target/Exec) as resource in .csproj's?

I'm doing a few shadereffects in a wpf_c# project and i don't know and i didn't find how to add the bytecode pixelshader (.ps) as Resource after be compiled by a target/exec.我在 wpf_c# 项目中做一些着色器效果,但我不知道,也没有找到如何在目标/执行程序编译后将字节码像素着色器 (.ps) 添加为资源。 This is my csproj code fragment:这是我的 csproj 代码片段:

<ItemGroup>
    <AvailableItemName Include="PixelShader"/>
</ItemGroup>
<ItemGroup>
    <PixelShader Include="Shaders\BlueToneShader.fx" />
    bla bla bla other shaders bla bla
</ItemGroup>
<Target Name="PixelShaderCompile" Condition="@(PixelShader)!=''" BeforeTargets="Build">
    <Exec Command="&quot;C:\Program Files (x86)\Windows Kits\10\bin\10.0.18362.0\x64\fxc.exe&quot; %(PixelShader.Identity) /T ps_3_0 /E main /Fo%(PixelShader.RelativeDir)%(PixelShader.Filename).ps" />
</Target>

Everything goes fine and the.ps files are correctly generated, as example:一切正常,正确生成了 .ps 文件,例如:

PixelShaderCompile:   
"C:\Program Files (x86)\Windows Kits\10\bin\10.0.18362.0\x64\fxc.exe" Shaders\BlueToneShader.fx /T ps_3_0 /E main /FoShaders\BlueToneShader.ps
Microsoft (R) Direct3D Shader Compiler 10.1 Copyright (C) 2013 Microsoft. All rights reserved.

compilation object save succeeded; see "folder"...

But now i dont know how to add that.ps file as 'Resource' during the compilation.但现在我不知道如何在编译期间将 that.ps 文件添加为“资源”。 Any one knows how?有谁知道怎么做? I didn't find any clear documentation.我没有找到任何明确的文件。

After 3-4 hours of trial-error i found a (i think dirty) way to do it: the msbuild (.csproj) looks like:经过 3-4 小时的试错后,我找到了一种(我认为很脏)的方法:msbuild (.csproj) 看起来像:

<PropertyGroup>
    <BuildDependsOn>
       PixelShaderCompile
       $(BuildDependsOn)
    </BuildDependsOn>
</PropertyGroup>
<ItemGroup>
    <AvailableItemName Include="PixelShader">
       <Visible>true</Visible>
    </AvailableItemName>
</ItemGroup>
<ItemGroup>
    <PixelShader ... />
    ...
</ItemGroup>
<Target Name="PixelShaderCompile" Condition="@(PixelShader)!=''" BeforeTargets="BeforeBuild;BeforeRebuild">
    <MakeDir Directories="$(IntermediateOutputPath)%(PixelShader.RelativeDir)" Condition="!Exists('$(IntermediateOutputPath)%(PixelShader.RelativeDir)')" />  
    //You put your fxc.exe command here
    <Exec Command="&quot;C:\bla bla bla\fxc.exe&quot; %(PixelShader.Identity) /T ps_3_0 /E PSmain /O3 /Fo$(IntermediateOutputPath)%(PixelShader.RelativeDir)%(PixelShader.Filename).ps" Outputs="$(IntermediateOutputPath)%(PixelShader.RelativeDir)%(PixelShader.Filename).ps">
          <Output ItemName="CompiledPixelShader" TaskParameter="Outputs" />
    </Exec>
    <ItemGroup>
        <Resource Include="@(CompiledPixelShader)" />
    </ItemGroup>
</Target>
//If you want to clear the .ps generated file 
<Target Name="PixelShaderClean" Condition="@(PixelShader)!=''" AfterTargets="AfterBuild;AfterRebuild">
    <Delete Files="$(IntermediateOutputPath)%(PixelShader.RelativeDir)%(PixelShader.Filename).ps" />
</Target>

That's it... So hard because there aren't so many made examples of msbuild files.就是这样......太难了,因为 msbuild 文件的示例并不多。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM