Copy always to output directory does not work

后端 未结 9 587
-上瘾入骨i
-上瘾入骨i 2020-12-30 18:49

I\'ve got a simple console project where I\'m reading two Excel-files. The Excel-files are included in the project (\"add existing item\") and I\'ve marked them with \"Copy

相关标签:
9条回答
  • 2020-12-30 19:02

    I had an issue when some png files was renamed-excluded-added again to project. It seemed that VS2015 had lost tracking what to do with these files: although in VS the "Copy to output directory: Copy always" was set at the problematic files, CopyToOutputDirectory key was not present in csproj file. I had to change csproj manually from

    <Content Include="xxx.png"/>
    

    to this:

    <Content Include="xxx.png">
        <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    
    0 讨论(0)
  • 2020-12-30 19:03

    Changes to non-source code files don't cause a rebuild to occur - they aren't considered when the compiler does it's out of date checking.

    Try forcing a complete rebuild by deleting your output directory completely (sometimes doing this from within Visual Studio isn't complete).

    It may be that the files haven't been copied across because a full build hasn't been run.

    0 讨论(0)
  • 2020-12-30 19:03

    VS 2015 behaves similarly, not updating the output directory correctly with Content files. What does seem to work, strangely, is to put a text file in the folder with the Content files and make it a Content file also. The text file will get copied to the directory and so will all the other Content files. Stranger still, if you then delete the text file, it will continue to show up in the output directory even though there is no longer an original to be copied.

    0 讨论(0)
  • 2020-12-30 19:08

    None of this worked for my WPF project. You need to mark it Content + Copy Always.

    Refer to this page for details on the different Visual Studio file properties.

    0 讨论(0)
  • 2020-12-30 19:12

    Silly question but are you running in debug mode? I've made the same mistake and realised I was in release mode.

    0 讨论(0)
  • 2020-12-30 19:12

    I put Content and Copy Always and it worked.

    0 讨论(0)
提交回复
热议问题