visual-studio 防止visual studio从bin/重建中删除所有内容?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2179856/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Keep visual studio from deleting everything from bin/ on rebuild?
提问by Earlz
I have a web application project. I have DLLs that I reference in the project stored in my bin/ folder. Well, whenever I do a rebuild or clean from Visual Studio, it will delete everything in that folder. How do I prevent this from happening?
我有一个 Web 应用程序项目。我在存储在 bin/ 文件夹中的项目中引用了 DLL。好吧,每当我从 Visual Studio 进行重建或清理时,它都会删除该文件夹中的所有内容。我如何防止这种情况发生?
采纳答案by billb
I'll stay away from asking the 'why' question and just state the how. Mark the files as read only and VS shouldn't delete them.
我将远离问“为什么”的问题,只说明如何。将文件标记为只读,VS 不应删除它们。
回答by John Saunders
Do not put anything into bin yourself. bin is the target folder for binaries - it is not a source folder for binaries.
不要自己往垃圾箱里放任何东西。bin 是二进制文件的目标文件夹 - 它不是二进制文件的源文件夹。
Create yourself a libfolder or something like that to put your third-party binaries into. You might even name it "Third Party Binaries", since not everyone knows that "lib" means the same thing. Make your references to the binaries in this folder, and Visual Studio will copy them into binwhen necessary (including on a rebuild).
为自己创建一个lib文件夹或类似的东西,将第三方二进制文件放入其中。您甚至可以将其命名为“第三方二进制文件”,因为并非所有人都知道“lib”的含义相同。引用此文件夹中的二进制文件,Visual Studio 会bin在必要时将它们复制到其中(包括重建时)。
回答by Hallgeir Engen
Follow John Saunders answer and put your .dll's into a separate folder. In my case I named this folder "ServerAssemblies". Then modify your project file (.csproj in my case) and add an "AfterRebuild" target.
按照 John Saunders 的回答,将您的 .dll 文件放入一个单独的文件夹中。就我而言,我将此文件夹命名为“ServerAssemblies”。然后修改您的项目文件(在我的情况下为 .csproj)并添加一个“AfterRebuild”目标。
<Target Name="AfterRebuild">
<ItemGroup>
<ExtraAssemblies Include="$(SolutionDir)ServerAssemblies\**\*.*"/>
</ItemGroup>
<Copy SourceFiles="@(ExtraAssemblies)" DestinationFolder="$(ProjectDir)bin\"></Copy>
</Target>
回答by Shrage Smilowitz
Can you explain why you have to store it in the bin folder to begin with? i always create a separate folder for example /components where i store all referenced dll's.
你能解释一下为什么你必须把它存储在 bin 文件夹中吗?我总是创建一个单独的文件夹,例如 /components,我在其中存储所有引用的 dll。
回答by Denny
One thing the "don't do it that way!" people are forgetting is source control and 3rd party software. Using SVN you often get files that if physical references were used would create mismatches when they're not in the same physical location.
一件事“不要那样做!” 人们忘记了源代码控制和 3rd 方软件。使用 SVN,您经常会得到一些文件,如果使用物理引用,当它们不在同一物理位置时会造成不匹配。
One CMS I'm working with at the moment prebuilds the VS project and solution when you set up another "instance" of it. It dumps in some dlls it needs... but if you rebuild they vanish.
当您设置另一个“实例”时,我正在使用的一个 CMS 会预构建 VS 项目和解决方案。它转储到它需要的一些 dll 中……但是如果您重建它们,它们就会消失。
The simple solution in both cases is to do as stated above and call it done.
在这两种情况下,简单的解决方案是按照上述方式进行操作并将其称为完成。

