Cannot compile CSCORE after retargeting to .NET 4.7.2

237 Views Asked by At

I retargeted the class library to 4.7.2 in order to be more recent and use CSCORE in a .NET Core 3.1 application that i am building.

I cant compile cause the post-build event returns -1:

Building on a Windows 10 machine with 2004 update.

Post-Build event :

@echo off & setLocal EnableDELAYedeXpansion
  chcp 65001

  set errorCode=0

  set target=$(TargetPath)
  set project=$(ProjectPath)

  set sdk=%PROGRAMFILES(x86)%\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools
  set framework=%WINDIR%\Microsoft.NET\Framework\v2.0.50727
  set inlineILCompiler=$(SolutionDir)Tools\InlineILCompiler\InlineILCompiler\bin\$(ConfigurationName)\InlineILCompiler.exe
  set cscli=$(SolutionDir)Tools\CSCli\bin\$(ConfigurationName)\CSCli.exe

  IF exist "%sdk%\." (
  echo OK: The Microsoft Windows SDK was found.
  ) else (
  echo FAILED: The Microsoft Windows SDK Dir was not found. Check the following path: "%sdk%"
  goto EXIT_ERR
  )
  IF exist "%framework%\." (
  echo OK: The .NET Framework Dir was found.
  ) else (
  echo FAILED: The Framework-Dir was not found. Check the following path: "%framework%"
  goto EXIT_ERR
  )
  IF exist "%inlineILCompiler%" (
  echo OK: Found the inline-il-compiler.
  ) else (
  echo FAILED: The inline-il-compiler was not found. Check the following path: "%inlineILCompiler%"
  goto EXIT_ERR
  )
  IF exist "%cscli%" (
  echo OK: Found the cscli-compiler.
  ) else (
  echo FAILED: The cscli was not found. Check the following path: "%cscli%"
  goto EXIT_ERR
  )

  if $(ConfigurationName) == Debug (
  echo Build-Configuration: DEBUG
  echo    DEBUG=IMPL
  echo    NO OPTIMIZE
  set ilasm_args=/DLL /DEBUG=IMPL
  ) else (
  if $(ConfigurationName) == Release (
  echo Build-Configuration: RELEASE
  echo    NO DEBUG
  echo    OPTIMIZE
  set ilasm_args=/DLL /OPTIMIZE
  ) else (
  echo FAILED: Invalid Configuration.
  goto EXIT_ERR
  )
  )

  echo.
  echo.
  echo Calling the inline-il-compiler ...
  call "%inlineILCompiler%"

  echo.
  echo.
  echo Calling CSCli ...
  call "%cscli%" -file:"$(TargetPath)" -r:"RemoveObjAttribute" -c:"CSCalliAttribute"

  :EXIT
  EXIT /B %errorCode%

  :EXIT_ERR
  set errorCode=-1
  goto EXIT
2

There are 2 best solutions below

0
Sajeeb Chandan Saha On

Just keep these 2 folders shown in the image on the directory of the directory of CSCore.csproj. I've been gone through this problem. I solved this way. If you need any more clarification on that please let me know.

Folder Structure

Now make sure that the project build order is like shown in the image.

enter image description here

0
Martin On

The CsCore compilation used a Post-Build script. In it there is a reference to the Microsoft SDK and Framework:

set sdk=C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.8 Tools
set framework=%WINDIR%\Microsoft.NET\Framework\v2.0.50727

The location of this sdk/framework depends on the windows version Windows 7 or Windows 10. in Studio, open CsCore properties and edit the postbuild script (alas not very readable because of LF only): you will have to change the SDK line to the SDK on your system. Change the ECHO OFF in ON so you see what happens. But it works.