2016-02-18 56 views
2

我想創建一個新的事件日誌事件來源我的WebAPI的應用程序登錄時,我進口申請通過IIS。VS發佈,Web部署 - 創建事件來源

我將我的應用程序發佈到VS2015中的Web部署文件夾(zip)文件並從中導入。

我發現這個代碼來創建事件源:

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

,我可以把這個在EventSource.ps1文件,我想要做什麼,當我從一個提示符下運行。

如何在IIS 導入應用程序過程中執行此操作?

我已經使用.pubxml文件,但該元素使用/覆蓋試圖/調用它,通過令我感到困惑 - 我已經試過AfterAddIisSettingAndFileContentsToSourceManifestPipelineDependsOn

<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應用導入完成後,作爲1命中過程,而不是一個:

  1. 進口申請
  2. 運行PowerShell的

因爲它將由非必要的技術用戶導入。

非常感謝您花時間協助!

回答

0

當應用程序導入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。我剛剛經歷過這個問題,讓我暫時偏離了軌道,因爲我遇到了一個我無法離開的錯誤。

僅供參考,這裏是.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> 

最後,這裏有一些資源,可以幫助:

+0

我給它一個去,謝謝。 – ninety

+0

我只注意到格式阻止了* .wpp.targets文件的一部分出現。這已被修復。 –