使用NuGet/Powershell从项目中删除文件夹和文件

Sco*_*den 14 powershell nuget nuget-package

我想在NuGet包安装期间从我的项目中删除App_Start文件夹.NuGet的文档在这里:

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

说:

$ project.Object相当于http://msdn.microsoft.com/en-us/library/ms170626.aspx.

我无法找到对我有帮助的界面的大量信息.

我有以下Powershell脚本成功删除文件夹和文件:

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
Run Code Online (Sandbox Code Playgroud)

(我知道此处的路径无法保证,但此包仅供内部使用)

但是项目仍然引用了项目,因此项目显示黄色警告,因为Visual Studio认为项目是项目的一部分.

我需要的是一种以编程方式从项目中删除对这些项的引用的方法.有任何想法吗?

Dan*_*eny 15

好吧,我绝对相信有比这更好的方法,但我从来没有使用过NuGet或Powershell直到今天......:/

我只是在我的包管理器控制台中运行它:

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

它遍历所有项目项目,寻找名为"控制器"的顶级项目,然后将其从项目中删除.很确定你可以把它改成"App_Code".

编辑:我的朋友(谁知道比我更多的Powershell)发送了这个:

$DTE.Solution.Projects|Select-Object -Expand ProjectItems|Where-Object{$_.Name -eq 'Controllers'}|ForEach-Object{$_.Remove()}
Run Code Online (Sandbox Code Playgroud)