2013-01-11 52 views
2

我目前使用VS2012中的內置發佈函數來發布ASP.NET MVC站點到Web服務器上的文件系統目錄共享。無論如何,當我點擊發布按鈕時,我可以將它發佈到多個位置,而不僅僅是發佈到多個位置。VS2012發佈到多個位置

我不想創建第二個配置文件,並且必須執行相同的過程兩次,並且我已經查看了修改pubxml文件的方法,方法是添加一個附加標記以查看發佈例程是否可以檢測它。但不幸的是,它似乎只是拿起列表中的最後一個配置。

我知道理想的是實施CI解決方案,但暫時我的手與發佈功能綁定在一起,需要保持相對簡單。

非常感謝

回答

1

您可以創建一個小的Windows服務,監視,當新文件添加

嘗試目錄,並複製到多個位置FileSystemWatcher on MSDN

+0

謝謝,我確實有這樣的一記夫婦的小事情,但我真的只是希望以某種方式把它所有的內如果可能,發佈功能和解決方案。但不錯的建議謝謝。 – Cragly

3

我們有同樣的需要發佈我們的解決方案到多個文件共享位置,而在幾個月前問這個問題的時候,我認爲一個答案可以讓社區受益。

由於VS發佈配置文件是普通的MSBuild文件,可以很容易地擴展,這裏是我帶來的解決方案。

請注意,我從我們的構建過程中提取了一些代碼片段,它有點複雜,所以我不保證它會在沒有改動的情況下工作。

在發佈配置文件中,我添加了一個自定義DeploymentPaths項目,如下所示。 請注意,您可以定義一個或多個其他位置。

<ItemGroup Label="Defines additional publish locations"> 
    <DeploymentPaths Include="\\SERVER1\ShareFolder\ProjectA\" /> 
    <DeploymentPaths Include="\\SERVER2\ShareFolder\ProjectA\" /> 
</ItemGroup> 

然後,我添加了一個自定義的目標CustomWebFileSystemPublishWebFileSystemPublish運行。該目標調用另一個MSBuild文件publish.xml,該文件執行刪除現有文件並複製新文件。

<!-- Custom File System Publish to deploy to additional locations based on DeploymentPaths --> 
<Target Name="CustomWebFileSystemPublish" AfterTargets="WebFileSystemPublish" Condition=" @(DeploymentPaths)!='' "> 
    <CreateItem Include="$(MSBuildProjectDirectory)\$(_PackageTempDir)"> 
    <Output ItemName="AbsoluteSourcePathItem" TaskParameter="Include" /> 
    </CreateItem> 
    <CreateProperty Value="%(AbsoluteSourcePathItem.Fullpath)"> 
    <Output PropertyName="AbsoluteSourcePath" TaskParameter="Value" /> 
    </CreateProperty> 

    <Message Text="### CustomWebFileSystemPublish" Importance="high" /> 
    <Message Text="### DeploymentPaths: @(DeploymentPaths)" Importance="high" /> 

    <MSBuild Projects="$(MSBuildProjectFile)" Properties="AbsoluteSourcePath=$(AbsoluteSourcePath)" Targets="DoPublish" /> 
</Target> 

<Target Name="DoPublish"> 
    <Message Text="### DoPublish $(AbsoluteOutputPath) | %(DeploymentPaths.Identity)" Importance="normal" /> 
    <!-- Adjust path to the publish.xml file depending on where you put it in your solution --> 
    <MSBuild Projects="..\Deployment\publish.xml" Properties="OutputPath=$(AbsoluteSourcePath);DeployPath=%(DeploymentPaths.Identity)" /> 
</Target> 

最後,這裏是publish.xml的MSBuild文件

<!-- Publish.xml --> 
<Project ToolsVersion="4.0" DefaultTargets="Default" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 
<Target Name="Start"> 
    <PropertyGroup> 
    <!-- Ensure DeployPath has the expected trailing slash --> 
    <DeployPath Condition=" '$(DeployPath)' != '' and !HasTrailingSlash('$(DeployPath)') ">$(DeployPath)\</DeployPath> 
    </PropertyGroup> 
    <Message Text=" # Deploying from $(OutputPath) to $(DeployPath) " Importance="normal" /> 
</Target> 

<Target Name="CleanDeployFolder" DependsOnTargets="Start" 
     Condition=" $(DeployPath)!=''"> 
    <Message Text=" # Cleaning files in $(DeployPath)" Importance="normal" /> 

    <!-- Defines the files to clean --> 
    <ItemGroup> 
    <DeployCleanFiles Include="$(DeployPath)\**\*.*" /> 
    </ItemGroup> 

    <!--Delete files in Deploy folder (folders not deleted by Delete Task)--> 
    <Delete Files="@(DeployCleanFiles)" /> 

    <Message Text=" # Cleaning files in $(DeployPath) Completed" Importance="normal" /> 
</Target> 

<Target Name="CopyToDeployFolder" DependsOnTargets="CleanDeployFolder" 
     Condition=" $(DeployPath)!=''"> 
    <Message Text=" # Copying files to $(DeployPath)" Importance="normal" /> 

    <ItemGroup> 
    <OutputFiles Include="$(OutputPath)\**\*.*" /> 
    </ItemGroup> 

    <Copy SourceFiles="@(OutputFiles)" DestinationFolder="$(DeployPath)%(OutputFiles.RecursiveDir)" /> 

    <Message Text=" # Copying files to $(DeployPath) Completed" Importance="normal" /> 
</Target> 

<Target Name="Default" DependsOnTargets="CopyToDeployFolder" 
     Condition=" $(OutputPath)!='' And $(DeployPath)!='' "> 
    <Message Text=" # Deploying from $(OutputPath) to $(DeployPath) Completed" Importance="normal" /> 
</Target> 
</Project>