Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove folder & files from project using NuGet/Powershell

I am trying to remove the App_Start folder from my project during my NuGet package install. The documentation for NuGet here:

http://nuget.codeplex.com/wikipage?title=Creating%20a%20Package

Says:

$project.Object is the equivalent of http://msdn.microsoft.com/en-us/library/ms170626.aspx.

Which I am not able to find much information of that interface that is of much help to me.

I have the following Powershell script which successfully removes the folder and files:

param($installPath, $toolsPath, $package, $project)

$DirInfo = New-Object System.IO.DirectoryInfo($installPath) 
$appDir = New-Object System.IO.DirectoryInfo($DirInfo.Parent.Parent.FullName)
$fullPath = [IO.Path]::Combine($appDir.FullName, $appDir.Name, "App_start")
Remove-Item $fullPath -recurse

(I know the pathing here isn't guaranteed, but this package is for internal use only)

But the project still has a reference to the items and therefore the items appear with the yellow warning because Visual Studio believes that the items are part of the project.

What I need is a way to remove a reference to those items from the project programatically. Any ideas?

like image 824
Scott Scowden Avatar asked Apr 26 '11 13:04

Scott Scowden


People also ask

How do I Delete a folder?

To remove a directory and all its contents, including any subdirectories and files, use the rm command with the recursive option, -r . Directories that are removed with the rmdir command cannot be recovered, nor can directories and their contents removed with the rm -r command.

How do I Delete a folder that won't Delete?

Delete the file/folder using Command PromptGo to Search and type cmd. Click on Run as administrator to open Command Prompt with full permissions. In the Command Prompt, enter del, followed by the path of the folder or file you want to delete, and press Enter (for example del c:usersJohnDoeDesktoptext.

How do I Delete a folder at once?

Right-click the Shell (folder) key, select New, and click on Key. Name the key Quick Delete and press Enter.

How do I Delete all folders?

To delete multiple files and/or folders: Select the items you'd like to delete by pressing and holding the Shift or Command key and clicking next to each file/folder name. Press Shift to select everything between the first and last item. Press Command to select multiple items individually.


1 Answers

Ok, I'm absolutely sure there's a better way than this, but I've never used NuGet or Powershell until today... :/

I just ran this in my Package Manager Console:

$DTE.Solution.Projects | ForEach { $_.ProjectItems | ForEach { if ($_.Name -eq "Controllers") { $_.Remove() } } }

It looped through all projects items looking for a top-level item called "Controllers" and then removed it from the project. Pretty sure you could just change this to "App_Code".

Edit: Friend of mine (who knows a little more Powershell than me) sent this:

$DTE.Solution.Projects|Select-Object -Expand ProjectItems|Where-Object{$_.Name -eq 'Controllers'}|ForEach-Object{$_.Remove()}
like image 124
Danny Tuppeny Avatar answered Oct 01 '22 00:10

Danny Tuppeny