question

AdamU-4420 avatar image
0 Votes"
AdamU-4420 asked karenpayneoregon commented

Nuget package creation and file removal on uninstall

Hi,

I am creating a package for use in dotnet core web applications. Specifically Umbraco 9 CMS. As of recent, it would appear that Powershell scripts are no longer used to populate and remove files on Nuget package installation/ uninstallation with the install and uninstall.ps1 scripts. It would appear that it is all managed using MsBuild and files are populated on build rather than package install. I have successful migrations on installation. The files are populated on a Build target by using a .targets file like so:

 <Target Name="CopyMyAssets" BeforeTargets="Build">
     <ItemGroup>
         <MyAssets Include="$(MyAssetsPath)" />
     </ItemGroup>
     <Copy SourceFiles="@(MyAssets)" DestinationFiles="@(MyAssets->'$(MSBuildProjectDirectory)\App_Plugins\MyPlugin\%(RecursiveDir)%(Filename)%(Extension)')" SkipUnchangedFiles="true" />
 </Target>

And therefore creating a removal method on clean was implemented like so:

 <Target Name="ClearMyAssets" BeforeTargets="Clean">
     <ItemGroup>
         <MyPluginDir Include="$(MSBuildProjectDirectory)\App_Plugins\MyPlugin\" />
     </ItemGroup>
     <RemoveDir Directories="@(MyPluginDir)"  />
 </Target>

My question is, on package uninstall through the Nuget package manager in Visual Studio, how do I ensure that these files are removed during the uninstall process? The user may not remember to clean before uninstalling, which will leave these orphaned files, and with no package to tell the project what to do, they will no longer be removed on subsequent cleans. Do I need to somehow invoke a project clean on uninstallation, or is there a way of scripting file removal? I have read the MsBuild documentation and I see no uninstall task or target for uninstall.

Any help would be greatly appreciated. Thanks.

dotnet-csharpdotnet-package-management
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

There is no task for invoking a clean operation which cleans out artifacts from the obj folder also.

0 Votes 0 ·

0 Answers