应用程序的.exe文件中缺少.NET TargetFramework,但只有在清洁的构建应用程序、清洁、文件、exe

2023-09-04 04:00:45 作者:Smile.過期℡

我有一个应用程序,我从VS2008转换到VS2012。该应用程序是混合模式,并取得了多个项目。升级后,在运行的应用程序崩溃,只要管理code输入与此异常:

I have an app I'm converting from VS2008 to VS2012. The app is mixed mode and made of multiple projects. After upgrading, the app crashes on run as soon as managed code is entered with this exception:

型System.TypeInitializationException的未处理的异常presentationFramework.dll

An unhandled exception of type 'System.TypeInitializationException' occurred in PresentationFramework.dll

附加信息:该类型初始值设定System.Windows.Application'引发了异常

Additional information: The type initializer for 'System.Windows.Application' threw an exception.

最深的内部异常是:

字符串不能是零长度参数名:frameworkName

"String cannot be of zero length. Parameter name: frameworkName"

堆栈跟踪是:

在System.Runtime.Versioning.BinaryCompatibility.ParseFrameworkName(字符串frameworkName,字符串和放大器;标识符的Int32和放大器;版本,字符串和放大器;型材)

如何把我的Java程序变成exe文件

at System.Runtime.Versioning.BinaryCompatibility.ParseFrameworkName(String frameworkName, String& identifier, Int32& version, String& profile)

在System.Runtime.Versioning.BinaryCompatibility.ParseTargetFrameworkMonikerIntoEnum(字符串targetFrameworkMoniker,TargetFrameworkId和放大器; targetFramework,的Int32和放大器; targetFrameworkVersion)

at System.Runtime.Versioning.BinaryCompatibility.ParseTargetFrameworkMonikerIntoEnum(String targetFrameworkMoniker, TargetFrameworkId& targetFramework, Int32& targetFrameworkVersion)

在System.Runtime.Versioning.BinaryCompatibility.ReadTargetFrameworkId()

at System.Runtime.Versioning.BinaryCompatibility.ReadTargetFrameworkId()

在System.Runtime.Versioning.BinaryCompatibility.get_AppWasBuiltForFramework()

at System.Runtime.Versioning.BinaryCompatibility.get_AppWasBuiltForFramework()

在System.Runtime.Versioning.BinaryCompatibility..cctor()

at System.Runtime.Versioning.BinaryCompatibility..cctor()

在一个干净的构建这只是发生,而且会发生在每次运行时,直到我清理一个单一的项目,然后重新编译。然后,它的工作原理我每次运行它​​。

This ONLY happens after a clean build, and will happen every time it runs, until I clean a single project and then build again. Then it works every time I run it.

我看着与JetBrains公司的.exe文件,比较他们看时,应用程序工作,当它崩溃像什么。当应用程序崩溃,这条线是.exe文件:

I looked at the .exe files with JetBrains and compared what they look like when the app works and when it crashes. When the app crashes, this line is in the .exe:

[总成:TargetFramework(,FrameworkDisplayName =.NET框架4)]

[assembly: TargetFramework("", FrameworkDisplayName = ".NET Framework 4")]

显然,框架字符串为空,并且导致了异常。当应用程序的工作原理,该行并不present,所以也不例外。

Obviously the framework string is blank, and that is causing the exception. When the app works, that line is not present, so no exception.

编辑净度:该应用程序的工作原理时,上面的一行是从.exe清单完全不存在。我已经证实,在VS2008,上面的线是不是在.exe文件清单。它看起来像它不应该在清单可言,而在VS2012上干净的建立是越来越增加,造成的问题。另外,我不使用一个app.config文件。

EDIT FOR CLARITY: The app works when the above line is totally absent from the .exe manifest. I have confirmed that in VS2008, the above line is not in the .exe manifest. It looks like it shouldn't be in the manifest at all, and on clean builds in VS2012 it is getting added and causing problems. Also, I am not using an app.config file.

有没有办法来解决这个问题?

Is there a way to fix this?

推荐答案

我一直在这方面的工作了3天,我只是找到了答案。

I've been working on this for 3 days and I just found the answer.

显然的MSBuild自动创建一个名为

Apparently MSBuild auto-creates a file called

.NETFramework,版本= v4.0.AssemblyAttributes.cpp

.NETFramework,Version=v4.0.AssemblyAttributes.cpp

C:\ Users \用户YOURNAME \应用程序数据\本地\温度

C:\Users\YOURNAME\AppData\Local\Temp

目录。创建您的.exe文件时,它使用这个文件。

directory. It uses this file when creating your .exe file.

在我的机器上这个文件包含以下内容:

On my machine this file contained the following:

#using <mscorlib.dll>
[assembly: System::Runtime::Versioning::TargetFrameworkAttribute(L"", FrameworkDisplayName=L".NET Framework 4")];

空字符串是造成我的问题。我改变了文件,可以说了:

The empty string was causing my problems. I changed the file to say this:

#using <mscorlib.dll>
[assembly: System::Runtime::Versioning::TargetFrameworkAttribute(L".NETFramework,Version=v4.0", FrameworkDisplayName=L".NET Framework 4")];

现在一切正常!我不知道如何将文件陷入这种状态,但我从来没有碰过它。我不认为这是在VS2008中使用。我有点苦恼,这样的文件在我的体型被使用。

Now everything works! I don't know how the file got into that state, but I never touched it. I don't think it's used in VS2008. I'm somewhat irked that such a file is being used in my build.