2015-11-04 65 views
0

由於我有多個配置,因此需要使用MSBuild在解決方案級別構建。我在發佈輸出的web項目中有一個自定義目標。我可以指定Web項目作爲目標,並且它可以很好地工作。但我需要發佈Web應用程序。在解決方案級別構建時有沒有辦法構建項目的自定義目標?MSBuild:在指定解決方案時構建自定義項目目標

我發現這個link,但我不明白解決方案。如果有人能夠稍微打破這一點,這將有很大幫助。

這是我目前的PowerShell命令行的樣子:

& "$env:windir\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe" ` 
    "..\..\Solution.sln" ` 
    "/t:WebApplication:PublishToFileSystem" ` 
    "/p:Configuration=$configuration;PublishDestination=$publishPath" 

:PublishToFileSystem導致它失敗,此消息:

error MSB4057: The target "PublishToFileSystem" does not exist in the project. [C:\Source\Solution.sln] 

這是我自定義的目標在我的。 csproj文件看起來像:

<Target Name="PublishToFileSystem" DependsOnTargets="PipelinePreDeployCopyAllFilesToOneFolder"> 
    <Error Condition="'$(PublishDestination)'==''" Text="The PublishDestination property must be set to the intended publishing destination." /> 
    <MakeDir Condition="!Exists($(PublishDestination))" Directories="$(PublishDestination)" /> 
    <ItemGroup> 
     <PublishFiles Include="$(_PackageTempDir)\**\*.*" /> 
    </ItemGroup> 
    <Copy SourceFiles="@(PublishFiles)" DestinationFiles="@(PublishFiles->'$(PublishDestination)\%(RecursiveDir)%(Filename)%(Extension)')" SkipUnchangedFiles="True" /> 
</Target> 

回答

0

因此,經過一些研究,我發現創建一個自定義目標不是發佈Web應用程序的最佳方式。假設您的解決方案中只有一個Web項目,MS擴展MSBuild以使用發佈配置文件(與在Visual Studio中發佈時使用的配置文件相同)。我能爲每個配置(環境)單獨發佈配置文件,並調用以下命令行:

& "$env:windir\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe" ` 
    "..\..\Solution.sln" ` 
    "/p:DeployOnBuild=true" ` 
    "/p:PublishProfile=$configuration" 

我必須確保我的發佈配置文件有相同的名字作爲我$configuration

publish profiles

相關問題