0

Hi I have tried to publish my c# project which have the following structure

C:\C-SHARP-PROJECTS
|
|--ProjectA
|    |--.vscode
|    |--ProjectA.sln
|    |--Libraries
|    |     |-- ConsoleMsgHelper.cs
|    |     |-- RenamerHelper.cs
|    |     |-- Libraries.csproj
|    |
|    |--ProjectA
|          |--.vscode
|          |-- Program.cs
|          |-- ProjectA.csproj
|
|--Releases
     |--myapp

Where ProjectA.csproj is:

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

  <ItemGroup>
    <ProjectReference Include="..\Libraries\Libraries.csproj" />
    <Content Update="*-exclude.dll">
      <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
        <ExcludeFromSingleFile>true</ExcludeFromSingleFile>
    </Content>
  </ItemGroup>

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net7.0</TargetFramework>
    <RuntimeIdentifiers>win10-x64</RuntimeIdentifiers>
    <PlatformTarget>x64</PlatformTarget> 
    <PublishSingleFile>true</PublishSingleFile>
    <IncludeAllContentForSelfExtract>True</IncludeAllContentForSelfExtract> 
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

</Project>

And Libraries.csproj is

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

  <PropertyGroup>
    <TargetFramework>net7.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>disable</Nullable>
  </PropertyGroup>

</Project>

I can execute dotnet build and also debug the program, however when i try to publish it by means of:

  • dotnet publish --output "c:/C-SHARP-PROJECTS/Releases/myapp" --runtime win-x64 --configuration Release -p:PublishSingleFile=true -p:PublishTrimmed=true --self-contained true or

  • dotnet publish --output "c:/C-SHARP-PROJECTS/Releases/myapp" --runtime win-x64 --self-contained true -p:PublishSingleFile=true -p:IncludeAllContentForSelfExtract=true or

  • dotnet publish --property:PublishDir="c:/C-SHARP-PROJECTS/Releases/myapp" --configuration Release --runtime win-x64 --self-contained true -p:PublishSingleFile=true -p:IncludeAllContentForSelfExtract=true

I get the following error: C:\Program Files\dotnet\sdk\7.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(94,5): error NETSDK1099: Publishing to a single-file is only supported for executable applications.. [C:\C-SHARP-PROJECTS\ProjectA\Libraries\Libraries.csproj]

grkikes
  • 29
  • 5

0 Answers0