Could not open configSource file that was added as a link

In my MVC application, I use external configuration files to keep clean web.config. Some files are shared, and I added them to the project as a link from one place. For these files, I set the Copy to copy always option, and these files are copied to the destination folder, and I see them. But when I try to open the homepage in the browser, I see the error "Unable to open configSource file." When I delete links to files and just add them (without a link), everything works fine. Any idea what might cause this error?

+11
source share
5 answers

Finally, I realized what the problem is. When using Copy, files are always copied to the bin folder. But files are searched in the virtual directory, not in the recycle bin. So I added a post assembly that copies the files to fix the destination.

+13
source

I added the post build event as suggested. But the exact steps are:

  • Right click on the project and go to properties
  • Go to the Build Events tab
  • At the command line of the Post-build event: I added:

xcopy / s "$ (ProjectDir) \ bin \ Config" "$ (ProjectDir) \ Config"

+6
source

I suffered from the same problem. In my case, the reason for this was the Build Action configuration property. (Right-click on the configuration file> Properties> Build Action)

Build Action has been set to None. After I changed it to "Content", the problem was resolved. (I'm not sure if it was a “Visual Studio error” or “my click on an error”, which made it “No”).

+4
source

See fooobar.com/questions/75845 / ... In short: you can add

<connectionStrings configSource="bin\Connections.config"> </connectionStrings> 

to distinguish between configuration (deployment / release version so debug / deploy). You can add transform . It is very convenient to use anyway.

(Yes, I know that the topic has been resolved, but maybe someone will find this information useful, like me)

0
source

After trying an xcopy solution that failed, the following worked for me:

Right-click cstrings.config, go to Properties .

Set the Copy to Output Directory property Copy to Output Directory Copy always

0
source

Source: https://habr.com/ru/post/1237781/


All Articles