Search code examples
c#rabbitmqnugetvisual-studio-2019

How can I clean the publish folder so a DLL doesn't keep getting copied to my website?


When building my solution, the most recent (v6.2.1) RabbitMQ.Client.dll ends up here: C:\inetpub\wwwroot\MyProject\RabbitMQ.Client.dll

I don't want that version. I referenced the latest RabbitMQ.Client.dll DLL in a project, by mistake, then undid that and referenced a previous version (v5.1.2), but the new one keeps showing up in wwwroot when building (we have a post-build event that publishes).

I cleared the NuGet cache, but it's still happening.

I searched for RabbitMQ.Client.dll in our solution folder and found these, all v6.2.1 (the new one, not what I want), in every one of our projects:
bin\Debug\netcoreapp2.2\publish\RabbitMQ.Client.dll

Is there a way to clear that folder? I'm guessing that's why the wrong version keeps ending up in wwwroot when building/publishing. Running Clean, in VS, doesn't do it.


Solution

  • Just add an automated MSBuild target to every your project's csproj file.

       <Target Name="DeletePreviousPublish" BeforeTargets="_CheckForUnsupportedTargetFramework">
    
        <RemoveDir Directories="$(PublishUrl.Remove($(PublishDir.LastIndexOf('\'))))"></RemoveDir>
    
       </Target>
    

    If your $(PublishDir) ends with \, you should use $(PublishDir.LastIndexOf('\'))) to make it as a folder so that RemoveDir will work.

    If not, just use

    <RemoveDir Directories="$(PublishDir)"></RemoveDir>.

    And then, when you click Publish button, it will first remove the previous publish folder and generate the new one. It is automatic, so you no longer need to manually delete the folder.

    Update 1

    It is quite an issue and should be automatic to remove the previous and then use the latest used ones. From a purely vs usage point of view, this is an obvious issue. I have reported the issue on our DC Forum.

    You can vote it and add any comments under the link if I did not describe the issue in detail. And hope the Team will fix the issue.

    Since the process will take a long time and for now, you have to use my solution to get what you want.