Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom "CoreLib" In .NET Core?

Trying to get a custom CoreLib in .NET Core project to load in VS 2017. This was super easy in .NET Framework as all you needed was "NoStdLib" but with .NET Core seems like a lot more parts are needed. I keep getting: "Project file is incomplete. Expected imports are missing."

<?xml version="1.0" encoding="utf-8"?>
<!--<Project Sdk="Microsoft.NET.Sdk">-->
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

  <PropertyGroup>
        <ProjectGuid>{3DA06C3A-2E7B-4CB7-80ED-9B12916013F9}</ProjectGuid>
    <OutputType>Library</OutputType>
    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>

    <!--<TargetFramework>netcoreapp2.2</TargetFramework>-->
        <GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
        <AddAdditionalExplicitAssemblyReferences>false</AddAdditionalExplicitAssemblyReferences>
        <ExcludeMscorlibFacade>true</ExcludeMscorlibFacade>
        <NoStdLib>true</NoStdLib>
        <NoCompilerStandardLib>true</NoCompilerStandardLib>

        <LangVersion>latest</LangVersion>
        <RootNamespace>System</RootNamespace>
  </PropertyGroup>

    <PropertyGroup>
    <AssemblyName>System.Private.CoreLib</AssemblyName>
    <AssemblyVersion>4.0.0.0</AssemblyVersion>
    <MajorVersion>4</MajorVersion>
    <MinorVersion>6</MinorVersion>
    <ExcludeAssemblyInfoPartialFile>true</ExcludeAssemblyInfoPartialFile>
  </PropertyGroup>

</Project>

Going off what System.Private.CoreLib.csproj is doing and not sure what the missing part is? Removing "Sdk="Microsoft.NET.Sdk"" causes part of the issue as I don't think I can have that for a custom corelib

What I'm basing this off of: https://github.com/dotnet/coreclr/blob/master/src/System.Private.CoreLib/System.Private.CoreLib.csproj

Does anyone know what the csproj settings are to get this working? I can't seem to find any good info on this.

like image 537
zezba9000 Avatar asked Feb 18 '19 23:02

zezba9000


1 Answers

Thanks to @PetSerAl: This does just what I needed. .NET Core fails to boot the lib (probably because my primitives, etc aren't implemented fully) but compiles all the IL I need for my project without errors.

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netcoreapp3.0</TargetFramework>
    <LangVersion>latest</LangVersion>

    <!-- Prevent .NET Core 3+ from generating exe -->
    <UseAppHost>false</UseAppHost>

    <!--Disable .NET Core SDK libs-->
    <NoStdLib>true</NoStdLib>
    <DisableImplicitFrameworkReferences>true</DisableImplicitFrameworkReferences>
  </PropertyGroup>

</Project>
like image 119
zezba9000 Avatar answered Oct 05 '22 17:10

zezba9000