skip to Main Content

This is pretty easy to replicate but also code here:

https://github.com/dominicshaw/dotnet-publish-error

  • create an empty wpf project using .NET7
  • create a publish profile for ClickOnce
  • publish via command line (not visual studio)

Publish profile is almost totally standard (view here)

Command line from project directory:

dotnet publish PublishError.csproj -p:PublishProfile=ClickOnceProfile

Subsequent error:

MSBuild version 17.4.0+18d5aef85 for .NET
  Determining projects to restore...
  All projects are up-to-date for restore.
C:Program Filesdotnetsdk7.0.100Microsoft.Common.CurrentVersion.targets(4149,5): error MSB4062: The "Microsoft.Build.Tasks.RequiresFr
amework35SP1Assembly" task could not be loaded from the assembly Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKey
Token=b03f5f7f11d50a3a.  Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, a
nd that the task contains a public class that implements Microsoft.Build.Framework.ITask. [C:UsersshawdsourcereposPublishErrorPubli
shErrorPublishError.csproj]

I have the latest SDKs installed and VS2022 up to date. This only happens via command line – I am able to publish from Visual Studio (I am setting up devops, so require command line).

This happens regardless of adding nuget package for Microsoft.Build.Tasks.Core. Note however nuget package v15.1.0.0 is not available – I have tried 15.1.548 and the latest instead.

Totally at a loss! Any ideas very welcome.

Thanks vm

2

Answers


  1. Chosen as BEST ANSWER

    A partial answer as my workaround for anyone struggling with a similar problem:

    I have found it impossible to do this with the dotnet cli but I can do it with MSBuild if I specifically target 17.4 (VS2022). By default, my Azure DevOps Server 2020 capability is the 2019 MSBuild (15.X), so I have to be explicit:

    "C:Program FilesMicrosoft Visual Studio2022ProfessionalMsbuildCurrentBinMSBuild.exe" /restore /Verbosity:m /t:Publish /p:RuntimeIdentifier=win-x64 /p:configuration=Release /p:PublishProfile=ClickOnceProfile

    This works - so in my pipeline I have created a batch file which runs this, then I copy the files to my ClickOnce location.

    Not ideal, but a working pipeline.

    Interesting side note - this dotnet cli command which should be idenitical (and indeed uses the correct 17.4 MSBuild) - does not work (with the same error):

    dotnet msbuild -target:Publish -property:RuntimeIdentifiers=win-x64;Configuration=Release;PublishProfile=ClickOnceProfile


  2. During the tests with your project and files, I finally managed to publish it successfully with the command dotnet publish PublishError.csproj -p:PublishProfile=FolderProfile.

    Here is the document for dotnet publish, as is referred,

    The preceding example uses the FolderProfile.pubxml file that is found
    in the <project_folder>/Properties/PublishProfiles folder. If you
    specify a path and file extension when setting the PublishProfile
    property, they are ignored. MSBuild by default looks in the
    Properties/PublishProfiles folder and assumes the pubxml file
    extension.

    And I also succeeded with dotnet publish with your project.

    ==============================

    update on 11/19

    So I suppose that the issue is resulted from your definition for -p:PublishProfile=ClickOnceProfile,it will change the path where this command would search for the publish file

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search