問題描述
需要從 VS2012 單元測試中識別我的 .csproj 文件 (Need to identify my .csproj file from VS2012 unit tests)
I am writing a unit test to validate duplicate entries in my .csproj file. However, these unit tests ran before the build process starts in server, hence my relative path to .csproj couldn't identify the physical path of my .csproj file.
Is there any workaround available to get the physical path of my .csproj file from unit test assembly.
Note: I have already tried using Assembly.GetExecutingAssembly(). This gives the current execution physical path of my unit tests file, but from that I can't navigate to my .csproj file.
參考解法
方法 1:
You need to let test know that the file is dependency so it copied as part of preparation of the test. Check out DeploymentItemAttribute and read related references.
Side note: unit test is strange place for such check... compiler should find duplicated CS files just fine...
方法 2:
You can use GetApplicationPath method to identify the project location
AssemblyHelper.GetApplicationPath()
(by KSH、Alexei Levenkov、Smaug)