是的app.config需要在.NET 4.0中C#项目? [英] Is app.config required in .Net 4.0 C# projects?

查看:338
本文介绍了是的app.config需要在.NET 4.0中C#项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

令我烦恼,Visual Studio 2010中添加的App.config文件到我所有的.EXE项目时,我改变了目标,从.NET Framework 3.5的到.NET Framework 4.0。所以,我的自动构建打破了,直到我在检查这些新文件。

Much to my annoyance, Visual Studio 2010 added App.config files to all of my .EXE projects when I changed the target from .NET Framework 3.5 to .NET Framework 4.0. So my automated build broke until I checked those new files in.

有没有什么特别的原因,我不能只是删除这些文件的App.config?或者是Visual Studio中去,让他们加入到我的项目?

Is there any particular reason I can't just delete these App.config files? Or is Visual Studio going to keep adding them to my projects?

我会从咆哮着的工具,增加了无用的文件到我的项目不要。 。

I'll refrain from ranting about a tool that adds useless files to my projects . . .

澄清:

我明白了什么的app.config 是。我不明白是为什么,当我更改项目的目标.NET 4.0而不是.NET 3.5的Visual Studio 2010将增加一个的app.config 文件,以现有的项目。为了运行我的应用程序并不需要任何的app.config,所以我唯一合理的结论是,无论是Visual Studio中由于某种原因需要在app.config以编译,或者有人决定,他们知道的比我更好,我的应用程序必须有一个app.config即使我不想之一。

I understand what app.config is for. What I don't understand is why Visual Studio 2010 would add an app.config file to an existing project when I change the project to target .NET 4.0 rather than .NET 3.5. My application doesn't require anything from app.config in order to run, so my only reasonable conclusion would be that either Visual Studio for some reason needs the app.config in order to compile, or somebody decided that they know better than me and my application must have an app.config even though I don't want one.

哎呀......我咆哮。

Oops ... I ranted.

进一步澄清:

从Visual Studio 2008转换项目到Visual Studio 2010是没有问题的。这是当我改变目标从.NET Framework 3.5的到在app.config被添加到项目中的.NET Framework 4.0。在app.config包含此:

Converting a project from Visual Studio 2008 to Visual Studio 2010 is not the problem. It's when I change the target from .NET Framework 3.5 to .NET Framework 4.0 that the app.config gets added to the project. The app.config contains this:

<configuration>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
  </startup>
</configuration>

当我改回为目标的.NET Framework 3.5,app.config文件被修改为

When I change it back to target .NET Framework 3.5, the app.config file is modified to read:

<supportedRuntime version="v2.0.50727"/>



我想我看到他们正在试图做什么,但补充说,app.config文件被自动一个非常糟糕的主意。

I think I see what they're trying to do, but adding that app.config file automatically was a really bad idea.

推荐答案

我知道app.config中的唯一的一次,要求在一个.NET 4项目如果引用一个CLR-2.0,混合模式组装。在这种情况下,你需要添加useLegacyV2RuntimeActivati​​onPolicy =真到startup元素,不然你会在运行时错误。

The only time I know of that app.config is required in a .NET 4 project is if you reference a CLR-2.0, mixed mode assembly. In that case, you need to add useLegacyV2RuntimeActivationPolicy="true" into the startup element, or you'll get errors at runtime.

不过,VS转换工具不检测此,并增加了在默认情况下一个app.config文件,该文件确实是没有必要的。如果你能够在转换后运行,这很可能不是你的问题。

However, the VS conversion tool does not detect this, and adds an app.config file by default that is really not necessary. If you are able to run after the conversion, this is likely not an issue for you.

另外,你可以自由地将其删除(除非,当然,你'重新将其用于其他目的)。

Otherwise, you are free to delete it (unless, of course, you're using it for other purposes).

这篇关于是的app.config需要在.NET 4.0中C#项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆