Visual studio 如何使用Visual Studio外部工具的长参数调用powershell.exe?

Visual studio 如何使用Visual Studio外部工具的长参数调用powershell.exe?,visual-studio,powershell,Visual Studio,Powershell,从Visual STudio外部工具中,我希望调用powershell脚本,如下所示: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe-command“{Add PSSnapin Microsoft.SharePOint.powershell-EA 0;”和“C:\my script.ps1”“-ProjectFile”“C:\customerprojet.csproj”“-WebPartDefinition”“的另一个很长路径

从Visual STudio外部工具中,我希望调用powershell脚本,如下所示:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe-command“{Add PSSnapin Microsoft.SharePOint.powershell-EA 0;”和“C:\my script.ps1”“-ProjectFile”“C:\customerprojet.csproj”“-WebPartDefinition”“的另一个很长路径\我的visual studio项目文件”“c:\my customerproject.xml”“}”中的一个\文件的另一个很长路径\指向我的visual studio项目文件的\路径”

实际上,我定义了使用一些令牌的外部工具:

-command{Add PSSnapin Microsoft.SharePOint.POwerShell-EA 0;&“C:\a非常长的路径,指向我的脚本,并带有空格\my script.ps1”“-ProjectFile”“$(ProjectFileName)”-WebPartDefinition”“$(ItemPath)”}

但是,此命令行超出了Windows允许的260个字符的限制,因此无法工作。在我的命令结束时,命令行似乎被截断(缺少
}

我怎样才能解决这个问题

[Edit]事实上,项目文件存在问题。令牌
$(ProjectFileName)
不包括项目目录,因此我必须改为:

-command{Add PSSnapin Microsoft.SharePOint.POwerShell-EA 0;&“C:\my script.ps1”“-ProjectFile”“$(ProjectFileName)\$(ProjectFileName)”“-WebPartDefinition”“$(ItemPath)””}

我还必须围绕ps1路径“三重”引用(但不理解为什么)

但是这不起作用。参数太长,visual studio禁止我使用此值

[Edit2]为了确定语法,下面是我如何从命令行成功调用脚本:

powershell-command”&{Add PSSnapin Microsoft.SharePOint.powershell-ea0;&“C:\path to\myscript.ps1”“-ProjectFile”“C:\Projects\someproject\someproject.csproj”“-WebPartDefinition”“C:\Projects\someproject\somefolder\somefile.xml”“-Verbose}”

可标记为:

powershell-command“&{Add PSSnapin Microsoft.SharePOint.powershell-EA 0;&”“C:\path to\myscript.ps1”“-ProjectFile”“”$(ProjectFileName)\$(ProjectFileName)”“”-WebPartDefinition”“(ItemPath)”“”-Verbose}”


但是命令行对于实际路径仍然太长:(

我在使用Dr.Memory时遇到了类似的问题

外部工具的参数字段只允许250个字符(我需要321个字符)


我可以通过创建一个批处理文件来解决这个问题。也许您可以将令牌作为参数传递给批处理文件,然后在批处理文件中生成完整的命令并从那里调用?

查看命令行可接受~8K个字符。编辑问题以添加您看到的错误消息,这样我们就可以自己进行推断我可能有misu了解此问题。请参阅我的编辑。如果希望在字符串中包含引号,我们将使用三重引号。您也可以使用严重重音引号而不是三重引号,如下所示:
“`“
是否尝试使用MSBuild xml文件调用powershell?如果是,请查看如何格式化命令字符串。否,我想从Visual Studio的外部工具调用脚本。这不是生成过程的一部分,而是生成一些代码(要处理的代码有点长)的脚本,该脚本应限定当前文件的范围。”