而不是使用項目屬性的預生成事件(我認爲是你的意思),重寫.csproj/.vbproj文件中的BeforeBuild目標。
<Project ...>
...
<Target Name="BeforeBuild">
<!-- Create the 'BuildScripts' directory. -->
<!-- The $(IntermediateOutputPath) reference the 'obj' folder, which I like to -->
<!-- use for these kinds of things. -->
<MakeDir Directories="$(IntermediateOutputPath)BuiltScripts">
<Output PropertyName="BuildScriptsPath" TaskParameter="DirectoriesCreated" />
</MakeDir>
<!-- Execute the javascript minifier. -->
<Exec Command="..." />
<!-- Create an item group for the minified scripts so we manipulate the target path. -->
<CreateItem Include="$(BuildScriptsPath)\*.js">
<Output ItemName="BuiltScripts" TaskParameter="Include" />
<Output ItemName="FileWrites" TaskParameter="Include" />
</CreateItem>
<!-- Add the minified scripts to the Content item group, -->
<!-- which the deployment MSBuild inspects for files to deploy. -->
<CreateItem Include="@(BuiltScripts)"
AdditionalMetadata="TargetPath=scripts\%(Filename)%(Extension)">
<Output ItemName="ContentWithTargetPath" TaskParameter="Include" />
</CreateItem>
</Target>
...
</Project>
您可能必須與該是CreateItem任務的輸出,如果文件沒有部署到正確的目錄內容項目組的形狀玩。請注意,我使用了一個項目轉換來製作目標路徑scripts\YourScript.js
。
另請注意,第一個CreateItem任務將輸出填充到名爲「FileWrites」的項目組中。我發現Clean目標檢查該項目組以知道要刪除的文件。
將XML放入您的項目文件後<Import>
元素,你應該很好去。不需要簽入源代碼控制,甚至你的構建服務器也會很開心。
你用什麼來部署\發佈 - 這是標準的msbuild目標或你做了一些自定義? –
@AlexeyShcherbak MSBuild,TFS,自定義 –
我懷疑Sayed Ibrahim Hashimi在回答你的問題後寫了這篇文章:)。 http://sedodream.com/2012/10/09/VSWebPublishHowToIncludeFilesOutsideOfTheProjectToBePublished.aspx –