简体   繁体   中英

Add a file to project resources using C#

I'm creating SpecFlow tests for an application that uses an xml settings file (example, C:\\ssis\\mySettingsFile.xml) to run. In one test, I want to save the file to disk, and then add that file to my project resources and clean up the disk location. Then, another test will unpack the resource to a temporary directory and use it from there.

I'm clear about the unpacking part, but is there a way to programatically pack the file into a project resource rather than manually adding it to the project using the VS GUI and marking it as an embedded resource?

I know this is wrong, but I'm thinking something along the lines of:

string myPath = "C:\ssis\mySettingsFile.xml";
TestHelper.ResourceDirectory = "$\...\...\Project.Folder.Resources";
myResource = TestHelper.PackResource(myPath);
myResource.IsEmbeddedResource = true;

...where PackResource method saves the file to the project resources.

Thanks in advance!

you can create a Resource Folder and add your xml to it. When you click on Properties of the project, there will be a Resources tab wherein you can see your file. To access the file, you can use ProjectNamespace.Properties.Resources.yourfilename.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM