How can I prevent bad project references?

主宰稳场 提交于 2019-12-06 03:37:52

Add a custom activity to your build process template. The activity's pseudo code should look like:

  • Execute before the compilation phase.
  • Loop all new changesets containing file extensions ending with *proj.
  • For all *proj files, search their contents for HintPath elements containing \Bin.
  • If results > 0, exit build with error, listing the policy failing projects.

To complete the solution also consider enforcing a custom check-in policy for the VS clients.

Since you are using PowerShell you might as well use it for this problem; the principle is straightforward: parse all csproj files and check if the HintPath doe not contain your Bin directory. In PowerShell that is something like (I've only just begun learning PS so there might be shorter ways):

# define path to bindir (or part of it) and main source dir
$binDir = path\to\Bin
$sourceDir = path\to\sourcefiles

# fix dots and slashes (or anything that cannot be used in regex
$binDirReg = $binDir -replace '\\', '\\' -replace '\.', '\.'

# parse
$res = Get-ChildItem -Recurse -Include *.csproj -Path $sourceDir |
       Select-String "HintPath>.*$binDirReg.*<"

if( $res )
{
  "ERROR somebody used Bin dir instead of Lib"
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!