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?
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.
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.
Right-click the Shell (folder) key, select New, and click on Key. Name the key Quick Delete and press Enter.
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.
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()}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With