Omkar
Omkar

Reputation: 1

Build Issue due to $(Platform) default value

We are facing build issue when we try to build .net project in custom project configuration, like Debug configuration we have added LinuxDebug as a configuration in project to target it for corss platform. But when we try to build using that configuration we are getting dependent project dll not found issue as its looking in different directory. In project file we have mentioned following $(SolutionDir)\Output\bin$(Platform)$(Configuration) the refered project is looking that dll in wrong directory, because somehow $(Platform) gets AnyCPU value, but at project level we have mentioned x64. we are not sure where exactly AnyCPU value gets assigned to $(Platform) referred/dependent dll is there in x64 directory. Can someone please help me here

I checked project properties build section's PlatformTarget where x64 is mentioned, and checked project configuration where also PlatformTarget set to x64, not sure how PlatformTarget gets AnyCPU value

Upvotes: 0

Views: 62

Answers (1)

Jason Pan
Jason Pan

Reputation: 22039

I create a brand new sample project which name is testdemo. According to your requirement, I add below configuration to support linuxdebug.

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

  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
     <!-- add this line for linux -->
     <RuntimeIdentifier>linux-x64</RuntimeIdentifier>
  </PropertyGroup>

    <!-- add custom configuration -->
    <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='LinuxDebug|x64'">
        <OutputPath>$(SolutionDir)\Output\bin\$(Platform)\$(Configuration)\</OutputPath>
        <PlatformTarget>x64</PlatformTarget>
        <DefineConstants>$(DefineConstants);LINUXDEBUG</DefineConstants>
    </PropertyGroup>

    <!-- Default configuration -->
    <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
        <PlatformTarget>AnyCPU</PlatformTarget>
    </PropertyGroup>

</Project>

Then I am using dotnet publish -c LinuxDebug -r linux-x64 --self-contained false command to test it. Here is the test result.

enter image description here

enter image description here

Upvotes: 0

Related Questions