Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 配置MSBuild以启动PowerShell并运行导入模块$(TargetFileName)_C#_Visual Studio_Powershell_Msbuild_Visual Studio 2013 - Fatal编程技术网

C# 配置MSBuild以启动PowerShell并运行导入模块$(TargetFileName)

C# 配置MSBuild以启动PowerShell并运行导入模块$(TargetFileName),c#,visual-studio,powershell,msbuild,visual-studio-2013,C#,Visual Studio,Powershell,Msbuild,Visual Studio 2013,我正在学习如何在c#中开发PowerShell模块,但没有Visual Studio集成来启动导入模块的PowerShell 我想将MSBuild配置为启动PowerShell并运行导入模块$(TargetFileName) 我将我的项目配置为库项目,并将调试选项设置为启动PowerShell,并将命令行参数设置为-NoExit-command“Import Module.\PowerShellModule.dll”。然而,我对这个解决方案并不满意 我的目标是在VisualStudio中按F5时

我正在学习如何在c#中开发PowerShell模块,但没有Visual Studio集成来启动导入模块的PowerShell

我想将MSBuild配置为启动PowerShell并运行导入模块$(TargetFileName)

我将我的项目配置为库项目,并将调试选项设置为启动PowerShell,并将命令行参数设置为-NoExit-command“Import Module.\PowerShellModule.dll”。然而,我对这个解决方案并不满意

我的目标是在VisualStudio中按F5时启动PowerShell,并加载我正在工作的模块和附加的调试器。理想情况下,我希望使用MSBuild宏创建可重用的模板,并避免使用csproj.user文件

以下是相关csproj.user文件:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
    <StartArguments>-NoExit -Command "Import-Module .\PowerShellModule.dll "</StartArguments>
    <StartAction>Program</StartAction>
    <StartProgram>C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe</StartProgram>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
    <StartAction>Program</StartAction>
    <StartProgram>C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe</StartProgram>
    <StartArguments>
    </StartArguments>
  </PropertyGroup>
</Project>

-NoExit-命令“导入模块。\PowerShellModule.dll”
节目
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
节目
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

通过在csproj的PropertyGroup下添加以下行,我能够实现我想要的

<StartAction>Program</StartAction>
<StartProgram>C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe</StartProgram>
<StartArguments>-NoExit -Command "Import-Module .\$(AssemblyName).dll"</StartArguments>
程序
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
-NoExit-Command“Import Module.\$(AssemblyName).dll”