Ara*_*and 7 deployment msbuild pre-build-event
我在Web项目上有一个预构建事件,它使用节点缩小和连接javascript文件.这将在脚本文件夹中创建一个名为BuiltScripts的文件夹,该文件夹是脚本文件夹的副本,但文件被缩小.当我进行部署时,我想发布脚本文件夹,包括其中的BuiltScripts文件夹.为此,我将BuiltScripts文件夹添加到项目中.这不是一个理想的解决方案:
我希望构建服务器构建并将javascript文件作为预构建步骤,但我不希望将BuildScripts文件夹添加到项目中.但是,当构建服务器在最后打包项目时,我希望它使用构建过程的输出复制BuiltScripts文件夹.我怎样才能做到这一点?
而不是使用项目属性的预构建事件(我认为这是你的意思),覆盖.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>
Run Code Online (Sandbox Code Playgroud)
如果文件未部署到正确的目录,则可能必须使用作为CreateItem任务输出的Content项组的形状.请注意,我使用项目转换来制作目标路径scripts\YourScript.js.
另请注意,第一个CreateItem任务将输出填充到名为"FileWrites"的项目组中.我发现Clean目标检查该项目组以了解要删除的文件.
在元素之后将XML放入项目文件中<Import>,你应该好好去.不需要检查源代码控制,甚至您的构建服务器也会很高兴.