Dotnet publishing via cmd not possible - c#

I'm successfully publishing a .NET Core App via Visual Studio but am unable to do the same via command-line (or using the Developer Command Prompt for VS 2019).
I'm using the Publish profile generated by VS2019 and doing:
dotnet publish -p:PublishProfile=Properties\PublishProfiles\MyProfile.pubxml
where MyProfile is:
<?xml version="1.0" encoding="utf-8"?>
<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>..\Build\Release\publish\</PublishDir>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<SelfContained>true</SelfContained>
<PublishSingleFile>False</PublishSingleFile>
<PublishReadyToRun>False</PublishReadyToRun>
<PublishTrimmed>False</PublishTrimmed>
</PropertyGroup>
</Project>
And the error that I always get is:
MyCustom.dll. Could not load type
'Microsoft.Build.Utilities.AppDomainIsolatedTask' from assembly
'Microsoft.Build.Utilities.Core, Version=15.1.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a'. Confirm that the
declaration is correct, that the assembly and all its dependencies are
available, and that the task contains a public class that implements
Microsoft.Build.Framework.ITask.
What am I missing?

I found a workaround, rather than a fix.
If we use msbuildto publish, I'm able to have the same result as dotnet publish and it runs successfully in the command-line:
msbuild /restore /t:Publish /p:RuntimeIdentifier=win-x64 /p:configuration=Release

Related

Azure Devops dotnet build don't respect configuration

In the csproj file of a project I have conditionals for TreatWarningsAsErrors.
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
</PropertyGroup>
On my computer running
dotnet build solution.sln --Configuration Debug
vs
dotnet build solution.sln --Configuration Release
produces the different results with success and failure as expected.
On our on-prem azure devops server however, even though the log clearly states "--Configuration Release" they show the problems as Warnings. Not failures as expected.
What can be wrong here?
The build log excerpts:
Starting: dotnet build
==============================================================================
Task : .NET Core
Description : Build, test, package, or publish a dotnet application, or run a custom dotnet command
Version : 2.181.0
Author : Microsoft Corporation
Help : https://learn.microsoft.com/azure/devops/pipelines/tasks/build/dotnet-core-cli
==============================================================================
C:\Windows\system32\chcp.com 65001
Active code page: 65001
Info: .NET Core SDK/runtime 2.2 and 3.0 are now End of Life(EOL) and have been removed from all hosted agents. If you're using these SDK/runtimes on hosted agents, kindly upgrade to newer versions which are not EOL, or else use UseDotNet task to install the required version.
F:\A\BUILDEDUI12C-B01\_work\_tool\dotnet\dotnet.exe build F:\A\BUILDEDUI12C-B01\_work\754\s\Modules\ScheduleMaker\Backend\ScheduleMaker.sln "-dl:CentralLogger,\"F:\A\BUILDEDUI12C-B01\_work\_tasks\DotNetCoreCLI_5541a522-603c-47ad-91fc-a4b1d163081b\2.181.0\dotnet-build-helpers\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll\"*ForwardingLogger,\"F:\A\BUILDEDUI12C-B01\_work\_tasks\DotNetCoreCLI_5541a522-603c-47ad-91fc-a4b1d163081b\2.181.0\dotnet-build-helpers\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll\"" --configuration Release -p:CustomBeforeMicrosoftCommonTargets=F:\A\BUILDEDUI12C-B01\_work\754\s\WE.CI.Tools.Build\Utilities\Education.SonarQube.ImportBefore.targets -p:SQProjectKey=WE.Education.ScheduleMaker
Microsoft (R) Build Engine version 17.1.1+a02f73656 for .NET
[warning]Modules\ScheduleMaker\Backend\Service\WE.Education.ScheduleMaker.Business\Services\ActivityService.cs(61,13): Warning S125: Remove this commented out code.
Edit:
From the diagnostics log i can see that the condition works, it says it changes the variable to True.
2022-04-14T07:06:33.6901214Z Property reassignment: $(TreatWarningsAsErrors)="True" (previous value: "false") at F:\A\BUILDEDUI12A-B01\_work\650\s\Modules\ScheduleMaker\Backend\Service\WE.Education.ScheduleMaker.Business\WE.Education.ScheduleMaker.Business.csproj (19,5)
But It dosen't act as it's true.
The solution, to get it listed as errors in Azure Devops was to add a property so it looked like this:
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
<MSBuildTreatWarningsAsErrors>False</MSBuildTreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
<MSBuildTreatWarningsAsErrors>true</MSBuildTreatWarningsAsErrors>
</PropertyGroup>
Then the setting was property forwarded in Azure Devops to.

Creating new blazor application throws an error when run

I am following Get started with Blazor. I have created the application and attempt to run it as is i have made no changes.
There are three things in my event log.
The directory specified for caching compressed content C:\inetpub\temp\IIS Temporary Compressed Files\Clr4IntegratedAppPool is invalid. Static compression is being disabled.
Application 'MACHINE/WEBROOT/APPHOST/WEBAPPLICATION1' with physical root 'C:\Users\LindaL\source\repos\Daimto.RazorTest.Tools\WebApplication1\' failed to start process with commandline 'c:\program files (x86)\microsoft visual studio\2017\professional\common7\ide\extensions\microsoft\web tools\projectsystem\VSIISExeLauncher.exe -argFile "C:\Users\LindaL\AppData\Local\Temp\tmpF272.tmp"', ErrorCode = '0x80004005' : 0.
Application 'MACHINE/WEBROOT/APPHOST/WEBAPPLICATION1' with physical root 'C:\Users\LindaL\source\repos\Daimto.RazorTest.Tools\WebApplication1\' failed to start process with commandline 'c:\program files (x86)\microsoft visual studio\2017\professional\common7\ide\extensions\microsoft\web tools\projectsystem\VSIISExeLauncher.exe -argFile "C:\Users\LindaL\AppData\Local\Temp\tmpF272.tmp"', ErrorCode = '0x80004005' : 0.
Note i just update to visual studio professional 2017 15.9.3. I have used blazor before this was working fine.
Update: This appears only in the "Blazor" project type.
Update2: hitting Cntrl-F5 as opposed to just F5 – No change.
Update3 Project file per request in comment in answer below
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<RunCommand>dotnet</RunCommand>
<RunArguments>blazor serve</RunArguments>
<LangVersion>7.3</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Blazor.Browser" Version="0.6.0" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.Build" Version="0.6.0" PrivateAssets="all" />
<DotNetCliToolReference Include="Microsoft.AspNetCore.Blazor.Cli" Version="0.6.0" />
</ItemGroup>
</Project>
Delete global.json and see if that helps.
https://github.com/aspnet/Blazor/issues/1342
If that doesn't help try adding global.json with content
{
"sdk": {
"version": "2.1.500"
}
}
If all fails, close all Visual Studio instances and reinstall Blazor templates with dotnet new -i Microsoft.AspNetCore.Blazor.Templates and create new Blazor solution with dotnet new and use Blazor template you want.

.net core 2.0 error running console app on ubuntu

I'm trying to run my first .net core 2.0 console app on ubuntu 16.04-x64.
I followed the steps to publish my app for ubuntu:
dotnet publish -c release -r ubuntu.16.04-x64
and also tried it from Visual Studio by changing my .csproj file like so:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
<RuntimeIdentifiers>ubuntu.16.04-x64</RuntimeIdentifiers>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="sharpadbclient" Version="2.1.0" />
<PackageReference Include="System.IO.Ports" Version="4.4.0" />
</ItemGroup>
</Project>
and then publish it with a publish profile.
I followed the instruction from Microsoft to install .net core on ubuntu.
I copied the published output to the PC running ubuntu ans when I'm trying to run the .dll file of my console app I'm getting this error:
Unhandled Exception: System.IO.FileLoadException:
Could not load file or assembly
'System.Console, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
The located assembly's manifest definition does not match the assembly reference.
(Exception from HRESULT: 0x80131040)
at LinuxVersion.Program.InitializeComponent()
at LinuxVersion.Program.Main(String[] args)
Aborted (core dumped)
When I'm running dotnet restore I'm getting a message saying:
MSBUILD : error MSB1003: Specify a project or solution file.
The current working directory does not contain a project or solution file.
Am I missing a step here in the process?
Well, turns out there is a difference between publishing the app using Visual Studio publish profile (right clicking on the project and selecting "publish") and using the command line.
When I used the Visual Studio publish profile I got this error, then I switched to using the command line like so: dotnet publish -c release -r ubuntu.16.04-x64
but to run it I went into the publish folder of the output: cd /home/MyApp/publish and then run the app using dotnet MyAppName.dll.
This solved it for me.

Using a publish profile with msbuild

I'm trying to use a publish profile with the msbuild command in a PowerShell window on a machine that does not have the full Visual Studio IDE installed. I have tried the following:
msbuild.exe .\Web.Admin.csproj /p:'DeployOnBuild=true;PublishProfile=Default;'
MSBuild.exe .\Web.Admin.csproj /p:PublishProfile=Default /p:VisualStudioVersion=14.0
msbuild.exe .\Web.Admin.csproj /p:PublishProfileRootFolder=C:\Users\username\Projects\Web\Web.Admin\Properties\PublishProfiles /p:PublishProfile=Default
In both cases, the publish profile seems to be ignored. This is the publish profile, generated by Visual Studio (in Properties\PublishProfiles\Default.pubxml):
<?xml version="1.0" encoding="utf-8"?>
<!--
This file is used by the publish/package process of your Web project. You can customize the behavior of this process
by editing this MSBuild file. In order to learn more about this please visit https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WebPublishMethod>FileSystem</WebPublishMethod>
<PublishProvider>FileSystem</PublishProvider>
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<SiteUrlToLaunchAfterPublish />
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
<ExcludeApp_Data>True</ExcludeApp_Data>
<publishUrl>C:\Sites\Test</publishUrl>
<DeleteExistingFiles>True</DeleteExistingFiles>
<PrecompileBeforePublish>True</PrecompileBeforePublish>
<EnableUpdateable>True</EnableUpdateable>
<DebugSymbols>False</DebugSymbols>
<WDPMergeOption>DonotMerge</WDPMergeOption>
</PropertyGroup>
</Project>
The files are not published to the C:\Sites\Test directory specified, as they would be if I ran this with the Publish command in Visual Studio 2017. Instead they go to the project bin directory.
MSBuild Version: 14.0.23107.0

.NET Core 1.1 app with PCL, unable to build on Team services

I have following projects on solution and this works perfectly fine on my local.
However when I check code in Team service and create build it fails.
mainconsole.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp1.1</TargetFramework>
<PackageTargetFallback>portable-net45+win8</PackageTargetFallback>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NETCore.Portable.Compatibility" Version="1.0.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\business\business.csproj" />
<ProjectReference Include="..\portableextensibility\portableextensibility.csproj" />
<ProjectReference Include="..\portablelibrary\portablelibrary.csproj" />
</ItemGroup>
</Project>
Build tasks:
command line - tool dotnet, argument - restore
command line - tool dotnet, argument - build
Build fails:
d:\a\3\s\portablelibrary\portablelibrary.csproj(43,3): error MSB4019: The imported project "C:\Program Files\dotnet\sdk\1.0.4\Microsoft\Portable\v4.5\Microsoft.Portable.CSharp.targets" was not found. Confirm that the path in the declaration is correct, and that the file exists on disk.
d:\a\3\s\portableextensibility\portableextensibility.csproj(42,3): error MSB4019: The imported project "C:\Program Files\dotnet\sdk\1.0.4\Microsoft\Portable\v4.5\Microsoft.Portable.CSharp.targets" was not found. Confirm that the path in the declaration is correct, and that the file exists on disk.
C:\Program Files\dotnet\sdk\1.0.4\NuGet.targets(97,5): error : Unable to resolve 'd:\a\3\s\portableextensibility\portableextensibility.csproj' for '.NETCoreApp,Version=v1.1'. [d:\a\3\s\dotnetcompatibility.sln] C:\Program Files\dotnet\sdk\1.0.4\NuGet.targets(97,5): error : Unable to resolve 'd:\a\3\s\portablelibrary\portablelibrary.csproj' for '.NETCoreApp,Version=v1.1'. [d:\a\3\s\dotnetcompatibility.sln] Generating MSBuild file d:\a\3\s\mainconsole\obj\mainconsole.csproj.nuget.g.props. Generating MSBuild file d:\a\3\s\mainconsole\obj\mainconsole.csproj.nuget.g.targets. Writing lock file to disk. Path: d:\a\3\s\mainconsole\obj\project.assets.json Restore failed in 37.7 sec for d:\a\3\s\mainconsole\mainconsole.csproj.
Errors in d:\a\3\s\business\business.csproj
Unable to resolve 'd:\a\3\s\portablelibrary\portablelibrary.csproj' for '.NETStandard,Version=v1.1'.
Errors in d:\a\3\s\mainconsole\mainconsole.csproj
Unable to resolve 'd:\a\3\s\portableextensibility\portableextensibility.csproj' for '.NETCoreApp,Version=v1.1'.
Unable to resolve 'd:\a\3\s\portablelibrary\portablelibrary.csproj' for '.NETCoreApp,Version=v1.1'.
Since the solution contains PCL libraries which currently cannot be built using the dotnet cli, the project has to be built through msbuild instead of the dotnet based commands.
Here is the corrected configuration:
Build Definition
Queue options
Result

Categories

Resources