Adding special target that will get a resource file and pass it to ilasm for S.R...
authorJose Perez Rodriguez <joperezr@microsoft.com>
Wed, 15 Aug 2018 23:42:38 +0000 (16:42 -0700)
committerGitHub <noreply@github.com>
Wed, 15 Aug 2018 23:42:38 +0000 (16:42 -0700)
* Adding special target that will get a resource file and pass it to ilasm for S.R.CS.Unsafe so that it has the right version headers

* PR Feedback

* Updating buildtools and fixing obj name

Commit migrated from https://github.com/dotnet/corefx/commit/e6506dbd5669b2996b3a1479e594e6e8a3a89774

src/libraries/BuildToolsVersion.txt
src/libraries/System.Runtime.CompilerServices.Unsafe/src/System.Runtime.CompilerServices.Unsafe.ilproj

index 0ff7fa7..d882819 100644 (file)
@@ -1 +1 @@
-2.2.0-preview1-03115-01
+2.2.0-preview1-03115-02
index f11ef4b..4f3f3e3 100644 (file)
     <Compile Include="System.Runtime.CompilerServices.Unsafe.il" />
     <Reference Include="System.Runtime" />
   </ItemGroup>
+
+  <Target Name="AddResourcesFileToIlasm" 
+          BeforeTargets="CoreCompile" 
+          Condition="'$(OS)'=='Windows_NT'"
+          Inputs="$(ContractOutputPath)/$(MSBuildProjectName).dll"
+          Outputs="$(IntermediateOutputPath)$(MSBuildProjectName).ref.res.obj">
+    <PropertyGroup>
+      <_IldasmCommand>$(ToolsDir)ilasm/ildasm.exe</_IldasmCommand>
+      <_IldasmCommand>$(_IldasmCommand) $(ContractOutputPath)/$(MSBuildProjectName).dll</_IldasmCommand>
+      <_IldasmCommand>$(_IldasmCommand) /OUT=$(IntermediateOutputPath)/$(MSBuildProjectName).ref.il</_IldasmCommand>
+
+      <!-- Try to use cvtres.exe from the framework and fallback to the one that is on the PATH in case we can't find it -->
+      <_CvtResCommand Condition="Exists('$(SystemRoot)\Microsoft.NET\Framework\v4.0.30319\cvtres.exe')">$(SystemRoot)\Microsoft.NET\Framework\v4.0.30319\cvtres.exe</_CvtResCommand>
+      <_CvtResCommand Condition="'$(_CvtResCommand)' == ''">cvtres.exe</_CvtResCommand>
+      <_CvtResCommand>$(_CvtResCommand) /MACHINE:x86</_CvtResCommand>
+      <_CvtResCommand>$(_CvtResCommand) /OUT:$(IntermediateOutputPath)$(MSBuildProjectName).ref.res.obj</_CvtResCommand>
+      <_CvtResCommand>$(_CvtResCommand) $(IntermediateOutputPath)$(MSBuildProjectName).ref.res</_CvtResCommand>
+    </PropertyGroup>
+
+    <ItemGroup>
+      <FileWrites Include="$(IntermediateOutputPath)$(MSBuildProjectName).ref.*" />
+    </ItemGroup>
+
+    <!-- Getting the res file by disassemblying the contract assembly -->
+    <Exec Command="$(_IldasmCommand)" ConsoleToMSBuild="true" StandardOutputImportance="Low">
+      <Output TaskParameter="ExitCode" PropertyName="_IldasmCommandExitCode" />
+    </Exec>
+    <Error Condition="'$(_IldasmCommandExitCode)' != '0'" Text="ILDasm failed while running command: &quot;$(_IldasmCommand)&quot;" />
+
+    <!-- Calling cvtres.exe which should be on the path in order to transform the resource file to an obj -->
+    <Exec Command="$(_CvtResCommand)" ConsoleToMSBuild="true" StandardOutputImportance="Low">
+      <Output TaskParameter="ExitCode" PropertyName="_CvtResCommandExitCode" />
+    </Exec>
+    <Error Condition="'$(_CvtResCommandExitCode)' != '0'" Text="cvtres failed while running command: &quot;$(_CvtResCommand)&quot;" />
+
+    <PropertyGroup>
+      <IlasmResourceFile>$(IntermediateOutputPath)$(MSBuildProjectName).ref.res.obj</IlasmResourceFile>
+    </PropertyGroup>
+  </Target>
 </Project>
\ No newline at end of file