简体   繁体   中英

Post-build events with MDB files in Visual Studio and Unity

My source code for my MonoBehaviours in Unity is not scripts inside the Assets folder, but compiled DLL's that I add as Plugins.

I have added post-build events in Visual Studio for my C# project, to try to get around the work with having to copy the DLL file and the MDB file every time I've changed something.

copy /Y "$(TargetDir)$(ProjectName).dll" "$(SolutionDir)\..\Assets\Plugins\$(ProjectName).dll"
copy /Y "$(TargetDir)$(ProjectName).dll.mdb" "$(SolutionDir)\..\Assets\Plugins\$(ProjectName).dll.mdb"

It works like a charm... almost. The problem I'm encountering, is that the DLL builds, then this command is run, but the MDB file hasn't had time to update yet, so I get an old MDB file copied to the Assets/Plugins folder.

Is there a way to wait for the MDB file to update before copying it?

I now have solution that works. Basically, the copying of the DLL and MDB files is part of the process of generating the MDB file from the PDB file in my C# project properties, as build targets, where the copy won't be performed until the MonoMdbGenerator is done executing.

<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="AfterBuild">
    <CallTarget Targets="GenerateMonoSymbols" Condition=" Exists('$(OutputPath)\$(AssemblyName).pdb') " />
</Target>
<Target Name="GenerateMonoSymbols">
    <Message Text="$(ProjectName) -&gt; $(TargetPath).mdb" Importance="High" />
    <Exec Command="$(MonoMdbGenerator) $(AssemblyName).dll" WorkingDirectory="$(MSBuildProjectDirectory)\$(OutputPath)" />
    <CallTarget Targets="CopyDLL" />
</Target>
<Target Name="CopyDLL">
    <Copy SourceFiles="$(OutputPath)\$(AssemblyName).dll" DestinationFolder="$(SolutionDir)..\Assets\Plugins\$(ProjectName)" />
    <Copy SourceFiles="$(OutputPath)\$(AssemblyName).dll.mdb" DestinationFolder="$(SolutionDir)..\Assets\Plugins\$(ProjectName)" />
</Target>

Some good reads on the subject:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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