3

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

我想将 MSBuild 配置为启动 PowerShell 并运行 Import-Module $(TargetFileName)。

我将我的项目配置为库项目并设置调试选项以启动 PowerShell 并将命令行参数设置为 -NoExit -Command "Import-Module .\PowerShellModule.dll"。但是我对这个解决方案并不满意。

我的目标是在我在 Visual Studio 中按 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>
4

1 回答 1

2

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

<StartAction>Program</StartAction>
<StartProgram>C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe</StartProgram>
<StartArguments>-NoExit -Command "Import-Module .\$(AssemblyName).dll"</StartArguments>
于 2013-10-22T23:08:49.690 回答