VS 2015 MSDeployPublish 未执行

VS 2015 MSDeployPublish not executing

我正在使用 VS 2015 并尝试在发布 Web 应用程序后执行 PowerShell。我已经创建了一个发布配置文件,在发布模式下编译并且发布方法是一个文件系统,然后在我的项目中 XML 我添加了一个目标

<Target Name="Mytarget2" AfterTargets="MSDeployPublish">
<Error Text="he name of the publish profile is $(DestinationAppRoot)">
</Error>
</Target>

所以我希望在通过 visual studio 发布后收到一条错误消息,但没有得到任何东西,如果我让它工作,我该如何调用 PowerShell 脚本?

VS 2015 MSDeployPublish not executing

那是因为您要从 File System 发布您的项目。 File System 不支持目标“MSDeployPublish”。

"We currently do not support executing custom targets after publish from VS for the file system protocol. If you publish from the command line the target will be executed however."

因此,您可以使用 MSBuild 命令行通过指定目标来执行此自定义目标,/t:Mytarget2:

msbuild "YourSolutionFile" /t:Build,Mytarget2 /p:DeployOnBuild=true /p:PublishProfile=YourPublishFile.pubxml

或者您可以更改 VS 中的设置以使用高详细度构建并查看哪个是最后执行的目标,然后您可以使用它代替目标 MSDeployPublish,例如 PipelineTransformPhase,所以自定义目标看起来像:

<Target Name="Mytarget2" AfterTargets="PipelineTransformPhase">
  <Error Text="he name of the publish profile is $(DestinationAppRoot)">
  </Error>
</Target>

希望对您有所帮助。