VS 发布、Web 部署 - 创建事件源



我想创建一个新的事件日志事件源,以便在通过 IIS 导入应用程序时记录我的 webAPI 应用。

我将应用程序发布到 VS2015 中的 Web 部署文件夹 (zip) 文件并从中导入。

我找到了创建事件源的代码:

if ([System.Diagnostics.EventLog]::SourceExists("myWeb.API") -eq $false) {
    [System.Diagnostics.EventLog]::CreateEventSource("myWeb.API", "Application")
}

我可以把它放在 EventSource.ps1 文件中,当我从提示符运行它时,它可以做我想要的。

如何在 IIS 导入应用程序过程中执行此操作?

我尝试过使用 .pubxml 文件,但使用/覆盖/调用它通过哪个元素让我感到困惑 - 我已经尝试了 AfterAddIisSettingAndFileContentToSourceManifestPipelineDependsOn

    <Target Name="CustomCreateEventSource">
    <Message Text="Create Event Source" Importance="high"/>
    <PropertyGroup>
        <EventSource Condition=" '$(EventSource)'=='' ">
            myWeb.API
        </EventSource>
    </PropertyGroup>
<Exec Command="powershell.exe"
-NonInteractive
-executionpolicy Unrestricted
-file &quot;$(PublishUrl)PublishEventSource.ps1&quot; &quot;$(EventSource)&quot;" /></Target>

我宁愿它通过 IIS 导入应用程序完成,作为一个 1 命中过程,而不是:

  1. 导入申请
  2. 运行电源外壳

因为它将由不一定是技术用户导入的。

非常感谢您抽出宝贵时间提供帮助!

在将应用程序导入 IIS 时,可以使用 <projectName>.wpp.targets 文件启动自定义命令。

例如,如果项目名称为 MyApp ,则将名为 MyApp.wpp.targets 的文件添加到项目的根级别。

我测试并验证了这种方法是否适用于具有以下内容的目标:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Target Name="CustomTask" AfterTargets="AddIisSettingAndFileContentsToSourceManifest">
    <ItemGroup>
      <MsDeploySourceManifest Include="runCommand">
        <!-- specify InputFormat None (see http://stackoverflow.com/questions/4238192/running-powershell-from-msdeploy-runcommand-does-not-exit) -->
        <Path>powershell.exe -ExecutionPolicy bypass -NoLogo -inputformat none -NonInteractive -Command .'$(_MSDeployDirPath_FullPath)DeploycreateEventLog.ps1'</Path>
      </MsDeploySourceManifest>
    </ItemGroup>
  </Target>
</Project>

需要注意的一件重要事情是,Visual Studio有时会缓存.wpp.targets文件。我知道发布它的唯一方法是重新启动Visual Studio。 我刚刚遇到了这个问题,这使我偏离了轨道一段时间,因为我遇到了一个我无法消除的错误。

作为参考,以下是我用于创建包 Zip 的.pubxml文件:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <WebPublishMethod>Package</WebPublishMethod>
    <LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
    <LastUsedPlatform>Any CPU</LastUsedPlatform>
    <SiteUrlToLaunchAfterPublish />
    <LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
    <ExcludeApp_Data>False</ExcludeApp_Data>
    <DesktopBuildPackageLocation>c:tempIISImportTestPkg.zip</DesktopBuildPackageLocation>
    <PackageAsSingleFile>true</PackageAsSingleFile>
    <DeployIisAppPath>Default Web Site/IISImportTest</DeployIisAppPath>
    <PublishDatabaseSettings>
      <Objects xmlns="" />
    </PublishDatabaseSettings>
  </PropertyGroup>
</Project>

最后,这里有一些资源可能会有所帮助:

  • 这就是我选择usin .wpp.targets文件的想法的地方:http://sedodream.com/2011/11/08/SettingFolderPermissionsOnWebPublish.aspx
  • 我在其中找到 runCommand 提供程序的 MsDeploy 提供程序列表:https://technet.microsoft.com/en-us/library/dd569040(v=ws.10).aspx

最新更新