none
TargetFrameworkAttribute of assembly RRS feed

  • Question

  • If you compile a project target to .NET 4.0 in VS2010SP1/.NET 4.0 SDK - the TargetFrameworkAttribute  is assigned as:

    • [assembly: TargetFramework(".NETFramework,Version=v4.0", FrameworkDisplayName=".NET Framework 4")]

    Also in VS2012 update1/.NET4.5 SDK, project tageted to .NET 4.0 will have the same value for the attribute as above.

    However, i have an assembly which is targeted .NET 4.0 and has TargetFrameworkAttribute :

    • [assembly: TargetFramework(".NETFramework,Version=v4.0.30319", FrameworkDisplayName="")]

    I dont know hwo this assembly was built - but I am wondering in what situation will such a value be assigned?

    Thank you

    PS:if you suggest me some enviroment/use case, i may not be able to create/simulate that environment immediately for testing - so, please let me know if you are sure about it. Thanks.

    • Moved by Bob Shen Friday, March 15, 2013 6:24 AM
    Thursday, March 14, 2013 9:49 PM

Answers

  • First, I'm sorry for the previous irrelevant post. The multi-targeting pack would not be related with this issue. Both versions of .NET Framework 4 and 4.0.3 are '4.0.30319'.

    After looking on the Internet, a TargetFrameworkVersion attribute is generated by MSBuild using TargetFrameworkMoniker property or TargetFrameworkVersion property.

    C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets:

    <TargetFrameworkVersion Condition=" '$(TargetFrameworkVersion)' == '' ">
      v4.0
    </TargetFrameworkVersion>
    <TargetFrameworkMoniker Condition=" '$(TargetFrameworkMoniker)' == '' "> $(TargetFrameworkIdentifier),Version=$(TargetFrameworkVersion) </TargetFrameworkMoniker>

    C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.CSharp.targets:

    [assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(
      &quot;$(TargetFrameworkMoniker)&quot;, 
    FrameworkDisplayName = &quot;$(TargetFrameworkMonikerDisplayName)&quot;)]

    Therefore, it is assumed that the value of TargetFrameworkVersion in *.csproj is 'v4.0.30319'. Then such project can not be opened in Visual Studio because of the following error: Project Target Framework Not Installed. However, if an MSBuild command line is used instead of the Visual Studio IDE, the build succeed with warning MSB3644: The reference assemblies for framework ".NETFramework,Version=v4.0.30319" were not found.

    I hope that this post can help you.

    Best regards

    • Marked as answer by _YatishK Friday, March 15, 2013 10:50 PM
    Friday, March 15, 2013 1:38 PM
  • Thanks a lot octopus-jelly.

    It turns out we had set TargetFrameworkVersion property to "v4.0.30319" in one of our build scripts.

    It has nothing to do with .NET4.5 and niether csproj file.

    Bu you get the credit - I am marking your suggestion as answer.

    Thanks a lot.

    Friday, March 15, 2013 10:50 PM

All replies

  • Thanks octopus-jelly for a great response.

    However, would installing multi-targeting pack automactically re-target all my .NET 4.0 projects to .NET 4.0.3? I think we'll have to explictely change the target?
    Also, wouldnt the project file then have: 
    <TargetFrameworkVersion>v4.0.3</TargetFrameworkVersion>

    I can confirm that this is not the case because in my source control the project file still has:
    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>

    On further investigation - it turned out that the developer on whose machine the targetframework v4.0.30319 assembly was generated, had VS2010 - but also had .NET framework 4.5 installed.

    When building the solution with some pre-existing essemblies (as references) they started getting errors/warning like following:
    warning MSB3275: The primary reference "MyLibrary, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL" could not be resolved because it has an indirect dependency on the assembly "AnotherLibrary, Version=1.0.0.0, Culture=neutral" which was built against the ".NETFramework,Version=v4.0.30319" framework. This is a higher version than the currently targeted framework ".NETFramework,Version=v4.0".

    Here MyLibrary was the pre-existing assembly and had target framework v4.0

    A clean build resolved the build issue (in which case I am assuming all binaries got the targetframework v4.0.30319).
    Unfortunately - I no longer have this dev enviroment to reproduce or verify.

    So, I am hoping to get some response from MSFT whether VS2010/.NET 4.5 combination would cause the assemblies to get such a target framework or is it that we hit some corner/buggy case in VS?

    I really want all my assemblies to have target framework v4.0 no matter what dev enviroment I use.

    Thank you.

    Friday, March 15, 2013 4:38 AM
  • First, I'm sorry for the previous irrelevant post. The multi-targeting pack would not be related with this issue. Both versions of .NET Framework 4 and 4.0.3 are '4.0.30319'.

    After looking on the Internet, a TargetFrameworkVersion attribute is generated by MSBuild using TargetFrameworkMoniker property or TargetFrameworkVersion property.

    C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets:

    <TargetFrameworkVersion Condition=" '$(TargetFrameworkVersion)' == '' ">
      v4.0
    </TargetFrameworkVersion>
    <TargetFrameworkMoniker Condition=" '$(TargetFrameworkMoniker)' == '' "> $(TargetFrameworkIdentifier),Version=$(TargetFrameworkVersion) </TargetFrameworkMoniker>

    C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.CSharp.targets:

    [assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(
      &quot;$(TargetFrameworkMoniker)&quot;, 
    FrameworkDisplayName = &quot;$(TargetFrameworkMonikerDisplayName)&quot;)]

    Therefore, it is assumed that the value of TargetFrameworkVersion in *.csproj is 'v4.0.30319'. Then such project can not be opened in Visual Studio because of the following error: Project Target Framework Not Installed. However, if an MSBuild command line is used instead of the Visual Studio IDE, the build succeed with warning MSB3644: The reference assemblies for framework ".NETFramework,Version=v4.0.30319" were not found.

    I hope that this post can help you.

    Best regards

    • Marked as answer by _YatishK Friday, March 15, 2013 10:50 PM
    Friday, March 15, 2013 1:38 PM
  • Thanks a lot octopus-jelly.

    It turns out we had set TargetFrameworkVersion property to "v4.0.30319" in one of our build scripts.

    It has nothing to do with .NET4.5 and niether csproj file.

    Bu you get the credit - I am marking your suggestion as answer.

    Thanks a lot.

    Friday, March 15, 2013 10:50 PM