summaryrefslogtreecommitdiff
path: root/Tools/GenerateAssemblyInfo.Sdk.targets
blob: ce5ab08e2ac015cd3d5c759f90703e2adaba0cdd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

  <PropertyGroup>
    <!-- BuildTools never generated this attribute before, so don't let the SDK generate it. -->
    <GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>

    <!--
    When using the Microsoft.NET.Sdk, Company and Product are defaulted to $(AssemblyName)
    in Microsoft.NET.Sdk.BeforeCommon.targets, which means we would have to default them in
    a props file. However, the versioning.props file has to be imported during versioning.targets
    in order to get all the version properties set correctly.
    So overwrite these two properties here, so they are set correctly.
    -->
    <Company>Microsoft Corporation</Company>
    <Product>Microsoft%AE .NET Framework</Product>
  </PropertyGroup>

  <Target Name="_ComputeBuildToolsAssemblyInfoAttributes"
          DependsOnTargets="CreateVersionFileDuringBuild;DecideIfWeNeedToIncludeDllSafeSearchPathAttribute"
          BeforeTargets="GetAssemblyAttributes">
    <ItemGroup>
      <AssemblyAttribute Include="System.Reflection.AssemblyDefaultAliasAttribute">
        <_Parameter1>$(AssemblyName)</_Parameter1>
      </AssemblyAttribute>

      <AssemblyAttribute Include="System.Reflection.AssemblyMetadata"
                         Condition="'$(SkipFrameworkAssemblyMetadata)' != 'true' and '@(AssemblyMetadata)' != ''">
        <_Parameter1>%(AssemblyMetadata.Identity)</_Parameter1>
        <_Parameter2>%(AssemblyMetadata.Value)</_Parameter2>
      </AssemblyAttribute>
    </ItemGroup>
  </Target>

  <!-- Work around https://github.com/Microsoft/msbuild/issues/3412 by writing the non-string assembly attributes manually -->
  <!-- Note: ReferenceAssemblies.targets still uses @(AssemblyInfoLines) as well. So if you remove this, those need to migrate too. -->
  <Target Name="_WriteNonStringAssemblyInfoAttributes"
          AfterTargets="CoreGenerateAssemblyInfo"
          Inputs="$(MSBuildProjectFile)"
          Outputs="$(AssemblyInfoFile)">

    <ItemGroup Condition="'$(MSBuildProjectExtension)' == '.csproj'">
      <AssemblyInfoLines Condition="'$(CLSCompliant)'=='true'" Include="[assembly:System.CLSCompliant(true)]" />

      <AssemblyInfoLines Condition="'$(IncludeDllSafeSearchPathAttribute)'=='true'"
        Include="[assembly: System.Runtime.InteropServices.DefaultDllImportSearchPathsAttribute(System.Runtime.InteropServices.DllImportSearchPath.AssemblyDirectory | System.Runtime.InteropServices.DllImportSearchPath.System32)]" />
    </ItemGroup>

    <ItemGroup Condition="'$(MSBuildProjectExtension)' == '.vbproj'">
      <AssemblyInfoLines Condition="'$(CLSCompliant)'=='true'" Include="&lt;Assembly:System.CLSCompliant(True)&gt;" />

      <AssemblyInfoLines Condition="'$(IncludeDllSafeSearchPathAttribute)'=='true'"
        Include="&lt;Assembly:System.Runtime.InteropServices.DefaultDllImportSearchPathsAttribute(System.Runtime.InteropServices.DllImportSearchPath.AssemblyDirectory | System.Runtime.InteropServices.DllImportSearchPath.System32)&gt;" />
    </ItemGroup>

    <WriteLinesToFile File="$(AssemblyInfoFile)"
                      Lines="@(AssemblyInfoLines)"
                      Condition="'@(AssemblyInfoLines)' != ''"
                      Overwrite="true" />

    <ItemGroup Condition="'@(AssemblyInfoLines)' != ''">
      <Compile Include="$(AssemblyInfoFile)" />
      <FileWrites Include="$(AssemblyInfoFile)" />
    </ItemGroup>
  </Target>

</Project>