从VSO到Azure网站构建时排除文件夹 [英] Exclude folder when building from VSO to Azure website
问题描述
我试图从Visual Studio Online中的Web项目部署到Azure网站中排除某些文件/文件夹.
该Web项目具有一个Content
文件夹,其中包含CSS,JS,构建脚本等,这些仅是开发所必需的,一旦部署到Azure,就可以从CDN加载CSS和JS.当前,从VSO进行的构建会将所有这些文件复制到Azure中的webroot,这是不必要的,并且对于构建脚本来说是潜在的安全问题.
I am trying to exclude certain files/folders from deployment of a web project in Visual Studio Online to an Azure website.
The web project has a Content
folder with CSS, JS, build scripts and so on, which are only necessary for development, once deployed to Azure the CSS and JS is loaded from a CDN. Currently the build from VSO is copying all those files to the webroot in Azure, which is unnecessary and a potential security issue in case of the build scripts.
现在我知道可以通过将文件的构建操作设置为None
来防止这种情况,但这是一个非常繁琐的解决方案,因为正在进行大量开发,新文件一直都在添加并且很容易忘记此设置.
Now I know this can be prevented by setting the build action of a file to None
, but this a very tedious solution because there is a lot of development going on, new files get added all the time and it is easy to forget this setting.
首先,我尝试在构建定义源设置中将Content
文件夹设置为Cloaked
,但这只会导致VSO在构建时不下载此文件夹,msbuild仍会抱怨这些文件丢失.
First I tried setting the Content
folder to Cloaked
in the build definitions source settings, but this only causes VSO to not download this folder on build, msbuild will still complain that those files are missing.
是否有一种方法可以告诉msbuild忽略整个Content
文件夹?我已经尝试在构建定义中将/p:ExcludeFoldersFromDeployment="Content"
作为msbuild参数添加,并且还在这里
Is there a way to tell msbuild to ignore the whole Content
folder? I already tried adding /p:ExcludeFoldersFromDeployment="Content"
as a msbuild argument in the build definition, and also tried the solutions in here How to get Visual Studio 'Publish' functionality to include files from post build event?, but nothing is working.
推荐答案
我正在研究 msbuild 日志文件,并提出了一个足以与我们一起使用的解决方案.
I was studying msbuild log files and came up with a solution that is good enough for us to work with.
我了解到的第一件事是,我无法阻止 msbuild 将具有生成操作Content
的文件复制到输出目录,至少没有更改 Microsoft.WebApplication.targets 文件,我不想这样做,甚至不确定是否可以使用VSO构建.
The first thing I learned was that I cannot prevent msbuild from copying files with build action Content
to the output directory, at least not without changing the Microsoft.WebApplication.targets file, which I didn't want to do and am not even sure is possible with VSO build.
无论如何,由于这个原因,我们无法在构建定义中将Content
文件夹的源设置设置为Cloaked
,因为这会导致构建失败.
Anyway because of this we cannot set the source settings of our Content
folder to Cloaked
in the build definition, since this will cause the build to fail.
此答案描述了我们最终要做的事情: https://stackoverflow.com/a/3140349/1230302
因此,通过将ExcludeFoldersFromDeployment
语句添加到 .csproj 文件中,将从Webroot中排除Content
文件夹.
What we ended up doing was described in this answer: https://stackoverflow.com/a/3140349/1230302
So by adding the ExcludeFoldersFromDeployment
statement to the .csproj file, the Content
folder is excluded from the webroot.
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
<OutputPath>bin\</OutputPath>
<ExcludeFoldersFromDeployment>Content</ExcludeFoldersFromDeployment>
</PropertyGroup>
这不是理想的解决方案,但是至少如果开发人员忘记将构建操作设置为None
,这种方式就不会部署任何东西.
It is not an ideal solution, but at least this way nothing gets deployed if a developer forgets to set the build action to None
.
这篇关于从VSO到Azure网站构建时排除文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!