File path for project files?

后端 未结 3 1567
忘了有多久
忘了有多久 2020-12-13 23:58

I am working on a media player in C# but when I want to make my test I have a problem.

I have to create a new object song with the following path:

@\         


        
3条回答
  •  盖世英雄少女心
    2020-12-14 00:54

    I was facing a similar issue, I had a file on my project, and wanted to test a class which had to deal with loading files from the FS and process them some way. What I did was:

    • added the file test.txt to my test project
    • on the solution explorer hit alt-enter (file properties)
    • there I set BuildAction to Content and Copy to Output Directory to Copy if newer, I guess Copy always would have done it as well

    then on my tests I just had to Path.Combine(Environment.CurrentDirectory, "test.txt") and that's it. Whenever the project is compiled it will copy the file (and all it's parent path, in case it was in, say, a folder) to the bin\Debug (or whatever configuration you are using) folder.

    Hopes this helps someone

提交回复
热议问题