[英]How do i read dll version in csproj file in C#
I want to write a Unit test for verifying version of dll used in all csproj files of a solution is correct or not. 我想编写一个单元测试来验证解决方案的所有csproj文件中使用的dll版本是否正确。 Ex. 防爆。 i have a dll reference in 1 csproj file like this 我像这样的1 csproj文件中有一个dll参考
<Reference Include="Moq, Version=4.2.1408.511, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\Moq.4.2.1408.0511\lib\net40\Moq.dll</HintPath>
</Reference>
so here i want to read Moq version as 4.2.1408.511 and compare with "4.2.1408.511" string. 所以在这里我想阅读Moq版本为4.2.1408.511并与“ 4.2.1408.511”字符串进行比较。 How can i write unit Test to do this 我该如何编写单元测试
I think this test isn't unit , it's integration . 我认为该测试不是单元 ,而是集成 。 Anyway, you can check version of an assembly in this way: 无论如何,您可以通过以下方式检查程序集的版本:
var anyTypeOfAssembly = typeof(Mock<>);
var targetAssembly = anyTypeOfAssembly.Assembly;
var versionInfo = FileVersionInfo.GetVersionInfo(targetAssembly.Location);
var fileVersion = versionInfo.FileVersion;
Assert.AreEqual("4.2.1408.511", fileVersion);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.