我可以在我拥有的_every_项目的同一目录中禁用 obj 的生成吗?
我正在整理我的项目。我找到了通过添加删除对象文件夹的方法: %TEMP%
在我的项目中。但我想以某种方式进行此全局设置或在构建后自动删除我的 obj 目录。有办法做到这一点吗?
I'm tidying my projects. And I found the way to remove the object folder with adding:
%TEMP%
In my projects. But I want somehow to make this global setting or to auto delete my obj dirs after a build. Is there a way to do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我个人喜欢在我的项目中有一个特定的
Output
文件夹,其中放置所有已编译的文件。我在构建后事件中有以下命令行。
这会将编译的文件复制到解决方案内的输出目录。您需要将其添加到解决方案中的所有项目中。
如果您有任何依赖项也需要复制,您也可以添加类似的内容。
[编辑]
您可以尝试以下操作来首先复制文件,然后在完成后删除对象文件夹。
[EDIT2]更新了屏幕截图以进行说明。 :)
这就是编译项目后我的对象文件夹通常的样子。
这是使用上述命令编译后的外观。正如您所看到的,该文件夹是在事件发生后由 Visual Studio 重新创建的,但该文件夹是空的。
您可能需要仔细检查您是否正在以提升的权限运行 Visual Studio。为此,只需右键单击 Visual Studio 并选择
“以管理员身份运行”
。I personally like having a specific
Output
folder in my project where I put all the compiled files.I have the following command line in the Post-build events.
This will copy the compiled file to the Output directory inside the Solution. You would need to add this to all the projects in your solution.
If you have any dependencies that also needs to be copied you could add something like this as well.
[EDIT]
You can try the following to have the file copied first, and then once that is done delete the object folder.
[EDIT2] Updated with screenshots to illustrate. :)
This is how my object folder normally would look like after compiling the project.
This is how it looks after compiling it with the above command. As you can see the folder is re-created after the event by Visual Studio, but the folder is empty.
You might want to double check that you are running Visual Studio with elevated permissions. To do so, simply right click on the Visual Studio and choose
"Run as Administrator"
.您使用源代码管理吗?
这个评论听起来你不这么认为:
(“存档”听起来有点像定期将整个项目文件夹复制到
backup_yyyymmdd
之类的位置)如果您不使用源代码管理,那么您应该明确考虑开始使用它。
除了一般优点(例如,具有日期和注释的更改历史记录......)之外,它还为您的 obj 文件夹问题提供了开箱即用的解决方案:
每个好的来源那里的控制软件支持忽略您可以定义的某些文件或文件夹(忽略意味着:它们永远不能提交到源存储库,您甚至在更改的文件列表中看不到它们,即使它们 已更改)。
例如,在 Mercurial (我使用的)中,忽略设置保存在名为
.hgignore 的文件中
在主文件夹中(Git 也有相同的,只是名为.gitignore)。
我的所有 Visual Studio 项目的默认
.hgignore
文件如下所示:第一行属于 Mercurial 的忽略语法,其余的是要忽略的设置。
您可以看到
bin
和obj
文件夹被忽略...并且无论它们位于哪个子文件夹中,它们都会被忽略!因此,我不必关心 obj 文件夹的实际位置,也不必每次构建解决方案时手动删除它们。它们在我的源代码管理历史中根本不存在。
另外,我对 Fuji 的答案有一个变体,即将所有内容放入一个输出文件夹中:
我也喜欢这样做,但我更喜欢在 Visual Studio 的项目设置中更改输出文件夹,而不是使用构建后事件。
默认输出文件夹是:
bin\Debug\
bin\Release\
我将它们更改为:
..\build\Debug\
..\build\Release\
这会将所有内容编译到
build
文件夹的子文件夹中,该文件夹与.sln
文件处于同一级别(这意味着:所有解决方案中的项目直接编译到同一文件夹中)。它还减少了编译时间,因为 Visual Studio 不必在编译后复制所有依赖项(因为所有内容都已位于同一文件夹中)。
(我这样做主要是因为编译时间,因为我忽略了
bin
和obj
文件夹无论如何在 Mercurial 中如上所述,所以我不在乎它们实际上在哪里)Are you using source control?
This comment sounds like you don't:
("Archiving" sounds a bit like copying the whole project folder regularly to something like
backup_yyyymmdd
)If you're not using source control, you should definitively consider starting to use it.
Apart from the general advantages (like, having a change history with dates and comments...), it has an out-of-the-box solution for your problem with the
obj
folders:Every good source control software out there supports ignoring certain files or folders which you can define (ignoring means: they can never be committed to the source repository, you don't even see them in the list of changed files, not even when they were changed).
For example, in Mercurial (which I use) the ignore settings are saved in a file named
.hgignore
in the main folder (Git has the same, it's just called.gitignore
).My default
.hgignore
file for all Visual Studio projects looks like this:The first line belongs to Mercurial's ignore syntax, the rest are the settings what to ignore.
You can see that the
bin
andobj
folders are ignored...and they are ignored no matter in which subfolder they are!So I don't have to care about where the obj folders actually are, and I don't have to delete them manually every time I build my solution. They are simply non-existent in my source control history.
Plus, I have a variation of Fuji's answer about putting everything in one single output folder:
I like to do this as well, but I prefer changing the output folders in Visual Studio's project settings instead of using post-build events.
The default output folders are:
bin\Debug\
bin\Release\
I change them to:
..\build\Debug\
..\build\Release\
This compiles everything into subfolders of a
build
folder which is at the same level like the.sln
file (which means: all projects in the solution directly compile into the same folder).It also reduces compile time because Visual Studio won't have to copy all the dependencies after compiling (because everything already is in the same folder).
(I do it mainly because of the compile time, because I ignore the
bin
andobj
folders anyway in Mercurial as described above, so I don't care where they actually are)