C
C#14mo ago
RT0405

✅ is there a way to delete or overwrite a dll during the postbuild event?

I'm trying to do some il weaving as a post build event, and I'd like to either overwrite the old dll, or make a new file and delete the old one, however I always get an IOException (another process is using this file) which I presume comes from msbuild still holding onto the file during the postbuild event. tldr: is there a workaround to allow automatic post build weaving in visual studio that I don't know of or am I missing something edit: here's my current csproj file, without the library references (if they matter I can add them)
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<AssemblyName>$(MSBuildProjectName)</AssemblyName>
<TargetName>$(MSBuildProjectName)unweaved</TargetName>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DebugType>embedded</DebugType>
</PropertyGroup>

<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="start ..\Velrdid.OpenXR.PostCompilerFixup\bin\Release\net6.0\Veldrid.OpenXR.PostCompilerFixup.exe" />
</Target>
</Project>
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<AssemblyName>$(MSBuildProjectName)</AssemblyName>
<TargetName>$(MSBuildProjectName)unweaved</TargetName>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DebugType>embedded</DebugType>
</PropertyGroup>

<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="start ..\Velrdid.OpenXR.PostCompilerFixup\bin\Release\net6.0\Veldrid.OpenXR.PostCompilerFixup.exe" />
</Target>
</Project>
2 Replies
Accord
Accord14mo ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.
RT0405
RT0405OP14mo ago
I found a work around using msbuild tasks to move and delete the old one
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<ItemGroup>
<DLLName Include="$(OutDir)$(MSBuildProjectName).dll" />
</ItemGroup>
<Move SourceFiles="@(DLLName)" DestinationFiles="@(DLLName -> Replace('dll', 'dll2'))" />
<Exec Command="start ..\Velrdid.OpenXR.PostCompilerFixup\bin\Release\net6.0\Veldrid.OpenXR.PostCompileFixup.exe"/>
<Delete Files="@(DLLName -> Replace('dll', 'dll2'))" />
</Target>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<ItemGroup>
<DLLName Include="$(OutDir)$(MSBuildProjectName).dll" />
</ItemGroup>
<Move SourceFiles="@(DLLName)" DestinationFiles="@(DLLName -> Replace('dll', 'dll2'))" />
<Exec Command="start ..\Velrdid.OpenXR.PostCompilerFixup\bin\Release\net6.0\Veldrid.OpenXR.PostCompileFixup.exe"/>
<Delete Files="@(DLLName -> Replace('dll', 'dll2'))" />
</Target>
and the il weaver reads from the dll2 file and outputs to a normal dll with the same name
Want results from more Discord servers?
Add your server