I created a unit testing to check the files. This can be put in a continuous integration server to check if files do exist in hard drive. Hopefully this can help somebody facing the same issue when working in a development team:
this sample runs a test in a file located at D:\YourProject\Solution\My.Website
a helper to deal with file IO in your test project (suppose it is on D:\YourProject\Solution\My.Website.Tests
)
internal sealed class IOHelper
{
/// <summary>
/// get list of files described in csproj
/// </summary>
/// <param name="filename"></param>
/// <returns></returns>
public static List<string> GetFilesInCSPROJ(string filename)
{
var list = new List<string>();
var lines = File.ReadLines(filename);
foreach (string line in lines)
{
if (line.Contains("<Content Include="))
list.Add(Regex.Matches(line, "(?:[^\"]+|\\.)*")[2].Value);
}
return list;
}
}
in your test project (suppose it is on D:\YourProject\Solution\My.Website.Tests
)
/// <summary>
/// Tests for CSPROJ
/// </summary>
[TestClass]
public class TestCSPROJ
{
/// <summary>
/// check if CSPROJ content files exist in disk
/// </summary>
[TestMethod]
public void CsProj_Files_Exist_In_Disk()
{
string root = Environment.CurrentDirectory.Substring(0, Environment.CurrentDirectory.IndexOf("\\Solution\\TestResults"))
+ "\\Website\\My.Website\\";
string websiteProj = root + "My.Website.csproj";
var list = IOHelper.GetFilesInCSPROJ(websiteProj);
Assert.IsTrue(list != null, "there are no content files added in Portal6.Website.csproj");
foreach (var item in list)
{
Assert.IsTrue(System.IO.File.Exists(root + item), "FAILED - file not found in disk: " + root + item);
}
}
}