You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[DeploymentItem] attribute is a no-op in the .Net Core world. This is however supported in Desktop and is required for functional testing scenarios and to provide isolation for test runs. Filing this work-item to add in that support for .Net Core based projects as well.
Steps to reproduce
In a .Net Core project add a DeploymentItem on a class/method linking to an xml resource(say) needed for the run.
Run a test that reads this xml resource.
Expected behavior
The test deploys the xml resource to a deployment directory and runs the test from there.
Actual behavior
The test fails complaining about not being able to find the resource file.
I am currently using this workaround for simple cases:
// Declare this property - this is set by MSTestpublicTestContextTestContext{get;set;}// In test initialization - note the signature should be exactly this// A static void method with one argument of type TestContext [TestInitialize]publicvoidTestSetup(){vartestName=TestContext.TestName;varmethod=newStackFrame().GetMethod().DeclaringType.GetMethod(testName);varattributes=method.GetCustomAttributes(typeof(DeploymentItemAttribute)).ToArray();foreach(DeploymentItemAttributeattinattributes){varorigin=Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),att.Path);vartargetDir=Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),att.OutputDirectory);// Creates dir for deployment itemDirectory.CreateDirectory(targetDir);// Copies itemtry{File.Copy(origin,targetDir);}catch(Exceptionex){System.Diagnostics.Debug.WriteLine("Error copying deployment item {0} to {1} message {2}",origin,targetDir,ex.Message);}}}
Activity
orellabac commentedon Feb 5, 2019
I am currently using this workaround for simple cases:
Adapter discovery for .net core projects (microsoft#96)
jayaranigarg commentedon Apr 10, 2019
Fixed with #565