asp.net – 从命令行包含项目中的文件
|
有没有办法在vs2012的命令行中包含项目中的文件? 我问的原因是因为每当我使用其他IDE(如ST3)或从Photoshop保存文件时,包含我添加到项目文件夹中的任何新文件都非常令人沮丧. 我正在使用Grunt进行大量的缩小,连接,在我的角度脚本上运行ngmin等.有一个grunt-shell插件允许grunt任务运行shell命令(我已经使用它来解锁TFS锁定的文件).所以我想我可以创建一个任务,为我添加的任何新文件(通过观看带有grunt-watch的特定文件夹)为我做项目中的包含. 解决方法这是使用Power Shell的解决方案.它有点长,但我保证它有效.我测试了很多.首先,简单的部分.以下是从命令提示符运行脚本的方法. powershell -File C:AddExistingItem.ps1 -solutionPath "C:Test.sln" -projectName "TestAddItem" -item "C:Test.txt" 现在可怕的部分,AddExistingItem.ps1: param([String]$solutionPath,[String]$projectName,[String]$item)
#BEGIN: section can be removed if executing from within a PowerShell window
$source = @"
namespace EnvDteUtils
{
using System;
using System.Runtime.InteropServices;
public class MessageFilter : IOleMessageFilter
{
//
// Class containing the IOleMessageFilter
// thread error-handling functions.
// Start the filter.
public static void Register()
{
IOleMessageFilter newFilter = new MessageFilter();
IOleMessageFilter oldFilter = null;
CoRegisterMessageFilter(newFilter,out oldFilter);
}
// Done with the filter,close it.
public static void Revoke()
{
IOleMessageFilter oldFilter = null;
CoRegisterMessageFilter(null,out oldFilter);
}
//
// IOleMessageFilter functions.
// Handle incoming thread requests.
int IOleMessageFilter.HandleInComingCall(int dwCallType,System.IntPtr hTaskCaller,int dwTickCount,System.IntPtr
lpInterfaceInfo)
{
//Return the flag SERVERCALL_ISHANDLED.
return 0;
}
// Thread call was rejected,so try again.
int IOleMessageFilter.RetryRejectedCall(System.IntPtr
hTaskCallee,int dwRejectType)
{
if (dwRejectType == 2)
// flag = SERVERCALL_RETRYLATER.
{
// Retry the thread call immediately if return >=0 &
// <100.
return 99;
}
// Too busy; cancel call.
return -1;
}
int IOleMessageFilter.MessagePending(System.IntPtr hTaskCallee,int dwPendingType)
{
//Return the flag PENDINGMSG_WAITDEFPROCESS.
return 2;
}
// Implement the IOleMessageFilter interface.
[DllImport("Ole32.dll")]
private static extern int
CoRegisterMessageFilter(IOleMessageFilter newFilter,out
IOleMessageFilter oldFilter);
}
[ComImport(),Guid("00000016-0000-0000-C000-000000000046"),InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]
interface IOleMessageFilter
{
[PreserveSig]
int HandleInComingCall(
int dwCallType,IntPtr hTaskCaller,IntPtr lpInterfaceInfo);
[PreserveSig]
int RetryRejectedCall(
IntPtr hTaskCallee,int dwRejectType);
[PreserveSig]
int MessagePending(
IntPtr hTaskCallee,int dwPendingType);
}
}
"@
Add-Type -TypeDefinition $source
[EnvDTEUtils.MessageFilter]::Register()
#END: section can be removed if executing from within a PowerShell window
$IDE = New-Object -ComObject VisualStudio.DTE
$IDE.Solution.Open("$solutionPath")
$project = $IDE.Solution.Projects | ? { $_.Name -eq "$projectName" }
$project.ProjectItems.AddFromFile("$item") | Out-Null
$project.Save()
$IDE.Quit()
#BEGIN: section can be removed if executing from within a PowerShell window
[EnvDTEUtils.MessageFilter]::Revoke()
#END: section can be removed if executing from within a PowerShell window
95%的代码只允许您从命令提示符运行.如果您直接在PowerShell中编写和运行代码,则可以将其保留并直接转到$IDE = New-Object -ComObject VisualStudio.DTE. Here是一篇博客文章,解释了为什么需要这些可怕的东西. 另一件值得注意的事情.我尝试使用EnvDTE程序集,就像在.net中一样,但我一直收到COM注册错误.一旦我开始使用COM对象直接一切正常.我不太了解COM真的冒险猜测为什么会这样. 编辑 如果在尝试从命令提示符运行脚本时收到此错误: 然后你需要先运行它(你应该只需要运行一次.) powershell -command“Set-ExecutionPolicy -ExecutionPolicy RemoteSigned” Here是对该命令正在做什么的一个很好的,深入的解释. (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- asp.net-mvc-2 – 检查Html.ValidationSummary()是否有值
- asp.net – 如何获取当前登录用户的角色列表
- asp.net gridview:如何在一列中包含多个按钮字段?
- ASP.NET:global.asax中的Access Session变量
- iis – 如何调试w3wp.exe随机崩溃的原因?
- asp.net-mvc – Asp.net MVC:上传多个图像文件?
- 如何在ASP.NET中的Web应用程序之间共享用户控件?
- asp.net-mvc – 在剃刀视图中启用和禁用文本框(ASP.Net MVC
- 优化 – 在经典ASP内存泄漏中实现对象缓存
- asp.net-mvc-3 – Html.RenderPartial和Ajax.BeginForm –
- asp.net-core – ClaimTypes的ASP.NET要求
- 如何衡量我在ASP.NET中的能力水平或技能?
- iis – Perfmon:哪个计数器标识线程正在等待?
- 发送电子邮件asp.net c#
- ASP.NET应用程序不反映区域设置
- CORS支持PUT和DELETE与ASP.NET Web API
- asp.net – 导致GridView无效回发的TemplateFiel
- asp.net-mvc-2 – Asp.Net MVC DropDownList数据
- asp.net-mvc – 添加视图模型类下拉列表不显示我
- asp.net-mvc – ASP.NET MVC4 CustomErrors Defa
