question

JuliusGermanicus-7390 avatar image
0 Votes"
JuliusGermanicus-7390 asked ksobieski commented

How to recover a file in Solution Explorer after set its "Build action" type as "Resourse"?

Hello! I'm having a problem with a file that I included in my project (is a simple text file). As it needed to be read by the program, I wanted it to be copy to the bin folder. In the past I think I did it by choosing the "Build action" type as "Content". But I think I selected "Resourse" by mistake and the file is now gone. The file is still in my project folder but in the solution explorer is hidden and it won't let me access the properties so I can change the Build action type. Can it be undone?Thanks!

vs-general
· 5
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

If you click on the Show All Files button in Solution Explorer, can you then see it and change its properties?

0 Votes 0 ·

Hej thanks for the reply.
No, it will only show the file in the same way it shows the .sln file. Like gray and not giving any possibility to change it.
Any ideas?

0 Votes 0 ·

I couldn't reproduce your situation; when I changed a file from Build Action: Content, to Resource, nothing other than that changed, and I could change it back afterwards.

I don't know why your .sln file is shown grey either- you normally don't see .sln files as such anyway, have you accidentally set the Solution Explorer Switch Views button on?

If your project is under version control, can you use that to determine what's changed?

0 Votes 0 ·

This just happened to me with a .NET Core 3.1 console app.

I added a file and changed its build option to Resource, then my .cs file un-included itself and the project will not build. The file cannot be re-added through the UI, when clicking the option, nothing happens.

Looks like this property change just corrupts the project.

0 Votes 0 ·

Not sure if you found a solution to this since it's an older thread, but I just ran into this issue. If you edit the project file, you'll likely see an ItemGroup that contains your files; it can be hard to pick out, but one of them is likely tagged <Resource ....>; if you change that to <Content ...> the file should reappear and have editable properties.

Hopefully this helps someone.

0 Votes 0 ·
DylanZhu-MSFT avatar image
0 Votes"
DylanZhu-MSFT answered

Hi JuliusGermanicus-7390,

After clicking on the "Show All Files" in solution explorer, you also need to include it into your project.
57120-image.png
Best Regards,
Dylan


If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


image.png (10.1 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

JuliusGermanicus-7390 avatar image
0 Votes"
JuliusGermanicus-7390 answered

Hey DylanZhu-MSFT and thanks for your reply!

Unfortunately I have already tried that and it did not work. That is why it is so strange. The only solution I found was to rename the file. After that, Visual Studio decided to see it again. In this case it was only a 9 MB text file so it does not matter much, but if the file was larger, mmm... I would not want to have to compile a dead file otherwise.
I will come back to this later when I finish this project.

Thanks again for your time!

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.