How to Build exe for SDK Simvars example

Can someone please share the configuration to build an exe for the Simvars application SimvarWatcher.

I build it but when it runs it immediately aborts, probably not putting the simconnect.dll in the right place.
How do I see the value of (ProjectDir)

in the Post Build there is

xcopy “$(ProjectDir)SimConnect.cfg” “.” /Y
xcopy “$(ProjectDir)…..\SimConnect SDK\lib\SimConnect.dll” “.” /Y

Old post, I know, but in case it helps anyone…

The Post Build event in my SimvarWatcher example looks like this (and I’m pretty sure I didn’t modify it):

xcopy "$(ProjectDir)SimConnect.cfg" "." /Y
xcopy "$(ProjectDir)..\..\SimConnect SDK\lib\SimConnect.dll" "." /Y

Notice the two steps back in the path instead of 1: ..\..\

Although in general one can also use the MSFS_SDK environment variable which should have been set for you when the SDK was installed. So I use this macro (in commands/referencing/linking/including).:

$(MSFS_SDK)\SimConnect SDK\lib\SimConnect.dll

Similarly for the package reference:

    <Reference Include="Microsoft.FlightSimulator.SimConnect">
      <HintPath>$(MSFS_SDK)\SimConnect SDK\lib\managed\Microsoft.FlightSimulator.SimConnect.dll</HintPath>
      <Private>true</Private>   <!-- copy it to output dir -->
    </Reference>

Of course if the build needs to be portable, eg. to run on a CI system w/out SimConnect installed, then those DLLs need to be copied to a local folder and included with the project (and referenced appropriately).

EDIT: And while I’m at it… to avoid the post build commands altogether, something like this could be used in the project file instead:

  <!-- SimConnect libs -->
  <ItemGroup>
    <Reference Include="Microsoft.FlightSimulator.SimConnect">
      <HintPath>$(MSFS_SDK)\SimConnect SDK\lib\managed\Microsoft.FlightSimulator.SimConnect.dll</HintPath>
      <EmbedInteropTypes>false</EmbedInteropTypes>
      <Private>true</Private>  <!-- copy it to output dir -->
    </Reference>
    <ContentWithTargetPath Include="$(MSFS_SDK)\SimConnect SDK\lib\SimConnect.dll">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <TargetPath>SimConnect.dll</TargetPath>  <!-- put it in the root of output dir -->
    </ContentWithTargetPath>
    <None Update="SimConnect.cfg">  <!-- assuming it's in the root of your project -->
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
  </ItemGroup>

HTH,
-Max

2 Likes