This has me completely baffled. I am testing upgrading our build infrastructure to .NET 4.5.2, which is currently on .NET 4.5.1.
My first step was to create an ASP.NET MVC project on my developer machine targeting .NET 4.5.2. I am using VS 2013 and have the 4.5.2 Developer Pack installed. I have written some superfluous code utilizing methods that are only supported in .NET 4.5.2:
public ActionResult Index()
{
if (!Response.HeadersWritten)
Response.AddOnSendingHeaders((c) => { c.Response.AddHeader("Foo", "Bar"); });
return View();
}
Response.HeadersWritten
and Response.AddOnSendingHeaders
are only introduced in the .NET 4.5.2 version of System.Web.dll
. As expected, this compiles fine locally.
Prior to upgrading the build server to 4.5.2 I thought I'd just run a build of the above project on the build server from source control to see it fail. However the build completes successfully, only reporting the following warning:
The reference assemblies for framework ".NETFramework,Version=v4.5.2" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the SDK or Targeting Pack installed. Note that assemblies will be resolved from the Global Assembly Cache (GAC) and will be used in place of reference assemblies. Therefore your assembly may not be correctly targeted for the framework you intend.
I pull down the compiled binaries from the drop to my local machine and the app runs fine and adds the foo
header.
How does this 4.5.2 code compile! There are no local references to System.Web checked into the source being built and there is nothing being pulled in through a nuget package or such.
答案 0 :(得分:1)
我已将此跟踪到GAC中System.Web.dll
的版本,该版本在构建期间被引用。尽管所有文档都指出Response.HeadersWritten
和Response.AddOnSendingHeaders
仅在.NET 4.5.2中引入,但.NET 4.5 / 4.5.1的以下安全更新将System.Web.dll的一个版本安装到GAC确实包含这些方法:
https://support.microsoft.com/en-us/kb/2894854
这解释了为什么编译仍然成功。当强制构建使用/p:TargetFrameworkVersion=v4.5.1
msbuild开关编译目标4.5.1时,System.Web.dll
引用是从以下位置提取的旧版本,它不包括那些方法,因此无法编译为预期:
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\System.Web.dll
答案 1 :(得分:0)
如果您的应用没有使用v4.5.2特有的任何内容(或者已经过时或以破坏方式更改),那么您应该做得很好。
当然,可能是B ^)你还没有遇到事情向南的特定执行路径。
此外,有人可能会注意到4.5.2 was an in-place update to 4.x family,因此无论您运行的是哪个4.x版本,都会获得相同的DLL。