2

I have some .NET projects in a solution. When I publish them, I'd like to publish just the DLL of my src projects, not the test ones.

Both https://github.com/dotnet/docs/issues/13365 and https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-publish#msbuild mention IsPublishable can be used to do so.

IsPublishable seems to be ignored for .NET 5 project.

I set at any test project the following

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

    <PropertyGroup>
        <TargetFramework>$(ApplicationTargetFramework)</TargetFramework>
        <IsPublishable>false</IsPublishable>
        <IsPackable>false</IsPackable>
    </PropertyGroup>
</Project>

but later, when I do a dotnet publish -c Release -o publish I can still see the test project *.dll and deps.json. Why? How to achieve what I want?

diegosasw
  • 13,734
  • 16
  • 95
  • 159

1 Answers1

0

There's probably something wrong I did. It works.

dotnet publish -o publish

will publish dll for each project.

If you add <IsPublishable>false</IsPublishable> on some *.csproj it won't publish those dll.

diegosasw
  • 13,734
  • 16
  • 95
  • 159
  • For me it worked when I published the whole solution (*.sln) instead of every project individually (**/*.csproj) – Radall Dec 06 '21 at 14:57
  • That command at solution level publishes all the projects within the solution at once. – diegosasw Dec 07 '21 at 15:11
  • Yes. I meant, then it actually applied the attribute, whereas it appeared to be ignored with individual projects. I was just saying, if someone has the same problem, they could try to switch from **/\*.csproj to *.sln – Radall Dec 07 '21 at 15:50
  • 1
    Ah I see. Well, it kind of make sense to be overridden imo. If you set a `*.csproj` as `IsPublishable` to `false` and then want to explicitly publish it with `dotnet publish` on that specific project, I'd like it to be published regardless. Not sure if it's as per design though. I rarely publish a single project. – diegosasw Dec 08 '21 at 16:07