gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 23:58:57 25 4
gpt4 key购买 nike

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

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

我发现以下代码可以创建事件源:

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

我可以将其放在EventSource.ps1文件中,该文件可以在从提示符处运行它时实现所需的功能。

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

我尝试使用.pubxml文件,但使用/覆盖/调用哪个元素使我感到困惑-我已经尝试了AfterAddIisSettingAndFileContentsToSourceManifest和PipelineDependsOn。
    <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)Publish\EventSource.ps1&quot; &quot;$(EventSource)&quot;" /></Target>

我希望它是通过IIS导入应用程序完成的,是一键式过程,而不是:
  • 导入应用程序
  • 运行powershell

  • 因为它将由不必要的技术用户导入。

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

    最佳答案

    当应用程序导入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)\Deploy\createEventLog.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:\temp\IISImportTestPkg.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
  • 关于powershell - VS发布,Web部署-创建事件源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35479458/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com