0
\$\begingroup\$

I'm trying to compile a .fxo file when I compile my game.

The compile command-line is:

fxc.exe /T fx_5_0 /Fo Basic.fxo Basic.fx

Instead of manually using fxc.exe, where can I put this in Visual Studio so when I compile the game, the .fxo gets generated?

\$\endgroup\$
1
  • \$\begingroup\$ Have you looked at hlsl tools for visual studio as that allows you to add your hlsl files in as resources. You then just load the object code. Unsure of effects files but I don use it CSO files. \$\endgroup\$
    – ErnieDingo
    May 16, 2018 at 4:00

1 Answer 1

1
\$\begingroup\$

The simplest solution is to add that command-line as a pre-build step in the project properties. The UI is slightly different for C++ versus C# projects, but basically involves the following steps:

  • Open the project's properties window.
  • Select the "Build Events" tab.
  • Type the appropriate command-line string into the "pre-build" text box.

You can apply the usual set of VS macros in these command-line strings.


A more involved, but more flexible, solution is to to edit the project's MSBuild directly to add a custom build tool. Both C++ and C# project files are actually MSBuild projects, so you can open them with a text editor (or within VS, if you unload them first) and edit the MSBuild commands directly.

For example, something like:

<ItemGroup>
  <CustomBuild Include="*.fx">
    <Message>Building shaders...</Message>
    <Command>fxc.exe /T fx_5_0 /Fo "$(OutDir)%(Filename).fxo" "%(Identity)"</Command>
    <Outputs>$(OutDir)%(Filename).fxo</Outputs>
  </CustomBuild>
</ItemGroup>

This is vastly more powerful, because you don't have to adjust the command-line for every new .fx file you add, and because MSBuild can be told about the relationship between inputs and outputs and thus avoids rebuilding things that aren't dirty... but at the same time, it's vastly more complex, because MSBuild is exactly that, and there can be quite a learning curve there.


There are also plugins and extensions you can find on the VS extensions marketplace to support this kind of stuff for you, if you'd rather go that route, although there are none I can personally recommend.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .