如何通过 nuget powershell 脚本重新加载 Visual Studio 项目 [英] How can I reload a visual studio project thru a nuget powershell script

查看:75
本文介绍了如何通过 nuget powershell 脚本重新加载 Visual Studio 项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在解决方案资源管理器中,DependentUpon"项目项通常被禁用为其他项(例如 web.config/web.Debug.config)的子项.我遇到的问题是,在安装包时通过 nuget/powershell 动态添加项目时,解决方案资源管理器不会重新加载项目,因此项目不会显示为依赖项.手动关闭并重新打开解决方案或卸载/重新加载项目可解决问题.我想作为 install.ps1 powershell 脚本的一部分自动执行 Project Reload,但是当我这样做时,我收到Project Unloaded"错误并且 nuget 回滚安装.我认为这是因为我知道如何获得 Reload 上下文菜单的唯一方法是先卸载项目.

In Solution Explorer 'DependentUpon' project items are normally disabled as children of the other item (ex. web.config / web.Debug.config). The problem I have is when items are dynamically added via nuget/powershell at package install, Solution Explorer doesn't reload the project so the items don't show as dependent. Manually closing and reopening the solution or unload/reload the project fix the issue. I'd like to automate the Project Reload as part of the install.ps1 powershell script but when I do this I get 'Project Unloaded' errors and nuget rolls back the install. I think this is because the only way I know how to get the Reload context menu is to unload the project first.

我正在寻找在此调用后面调用的对象.我想如果我可以直接执行,我就不用先卸载项目了.

I'm looking for the object that gets invoked behind this call. I think if I could execute directly, I wouldn't have to Unload the project first.

$dte.ExecuteCommand("Project.ReloadProject")

这是在解决方案资源管理器中卸载/重新加载项目的完整代码

And here is the full code to unload/reload the project in Solution Explorer

# Reload a project thru dte/SolutionExplorer Window 
# using Unload and Reload Context Menus.

$project = Get-Project
$shortpath = $dte.Solution.Properties.Item("Name").Value + "\" + $project.Name

#following GUID = Constants.vsWindowKindSolutionExplorer
#magic 1 = vsUISelectionType.vsUISelectionTypeSelect
$dte.Windows.Item("{3AE79031-E1BC-11D0-8F78-00A0C9110057}").Activate()
$dte.ActiveWindow.Object.GetItem($shortpath).Select(1)
$dte.ExecuteCommand("Project.UnloadProject")
$dte.ExecuteCommand("Project.ReloadProject")

推荐答案

类似的问题在这里回答:VS 2010 中是否有允许它在项目文件更改后恢复打开的文件的设置?但是,它并不表示可以在不首先调用 unload 的情况下调用 reload,并且它没有提供一种无需通过 dte.executecommand 直接调用的机制.

Similar question answered here: Is there a setting in VS 2010 that will allow it to recover open files after a project file changes? However, it doesn't indicate that reload can be called without first calling unload and it doesn't provide a mechanism for calling directly w/o going thru dte.executecommand.

这篇关于如何通过 nuget powershell 脚本重新加载 Visual Studio 项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆