dotnet / sdk

Core functionality needed to create .NET Core projects, that is shared between Visual Studio and CLI
https://dot.net/core
MIT License
2.69k stars 1.06k forks source link

Publish cannot find compiled output of local project dependency #11441

Open alecxvs opened 4 years ago

alecxvs commented 4 years ago

I have a solution that consists of two projects:

  1. "WindowsApp", a netcoreapp3.1 WPF project which depends on "Lib"
  2. "Lib", a netstandard2.1 library (with a netcoreapp3.1 target in order to use EF Core Tools)

And I'm using Visual Studio 2019

I'm trying to publish my application as a single file executable, but publish keeps failing:

Metadata file 'C:\repos\MySolution\Lib\bin\Release\netstandard2.1\win-x86\Lib.dll' could not be found

It seems to be looking in bin\Release\netstandard2.1\win-x86\ for the library instead of bin\Release\netstandard2.1\.

This seems to present an identical error but I'm not sure the root cause of the error was ever discovered: https://github.com/dotnet/aspnetcore/issues/11088

WindowsApp.csproj

<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFrameworks>netcoreapp3.1</TargetFrameworks>
    <StartWorkingDirectory>$(MSBuildProjectDirectory)</StartWorkingDirectory>
    <UseWPF>true</UseWPF>
    <StartupObject>WindowsApp.App</StartupObject>
  </PropertyGroup>

  <ItemGroup>
    <ProjectReference Include="..\Lib\Lib.csproj">
      <SetTargetFramework>TargetFramework=netstandard2.1</SetTargetFramework>
    </ProjectReference>
  </ItemGroup>
</Project>

Lib.csproj

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFrameworks>netcoreapp3.1;netstandard2.1</TargetFrameworks>
    <OutputType>Library</OutputType>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.3" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.1.3" />
  </ItemGroup>

  <ItemGroup Condition="'$(TargetFramework)' != 'netstandard2.1'">
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.3">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.3">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
  </ItemGroup>

  <ItemGroup>
    <Folder Include="migrations\" />
  </ItemGroup>
</Project>

publishApp.pubxml (under WindowsApp)

<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121. 
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <PublishProtocol>FileSystem</PublishProtocol>
    <Configuration>Release</Configuration>
    <Platform>Any CPU</Platform>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <PublishDir>..\bin\</PublishDir>
    <RuntimeIdentifier>win-x86</RuntimeIdentifier>
    <SelfContained>false</SelfContained>
    <PublishSingleFile>True</PublishSingleFile>
    <PublishReadyToRun>True</PublishReadyToRun>
  </PropertyGroup>
</Project>
alessandrofrancesconi commented 3 years ago

Same issue here, with similar project structure. VS for Windows version 16.8.2 .NET Core SDK 3.1.402

brinko99 commented 1 year ago

Same issue with VS2022 and NET6. I can work around the errors by manually copying the files to the requested location.

Attention here would be highly appreciated.