简体   繁体   中英

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?

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()}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM