Dot-Net

DeploymentItemAttribute 的相對路徑根是什麼?

  • October 31, 2017

使用MSTest , DeploymentItemAttribute的相對路徑根是什麼。

根據MSDN頁面…

相對路徑相對於 .testrunco​​nfig 文件中的 RelativePathRoot 設置。

預設情況下,該設置是解決方案目錄。所以,如果你有這個項目結構

SecretProject\
   ComponentA\
   ComponentA.Test\
       Resources\
           required.xml
       ComponentA.Test.csproj
       Tests.cs
   SecretProject.sln

你想部署required.xml,你要像這樣創建一個 DeploymentItemAttribute

[TestClass]
public class Tests
{
   [TestMethod]
   [DeploymentItem("ComponentA.Test\Resources\required.xml")]
   public void Test() 
   {

   }
}

似乎需要將文件屬性設置為“內容”和“始終複製”或“如果較新則複製”。此 MSDN 頁面上有高級範例。

引用自:https://stackoverflow.com/questions/1822612