而不是使用项目属性的预生成事件(我认为是你的意思),重写.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 –