I have the following pubxml file which I created via Visual Studio 2019:
<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>False</ExcludeApp_Data>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<ProjectGuid>143a6329-27d9-474e-9521-835be634c293</ProjectGuid>
<SelfContained>true</SelfContained>
<publishUrl>bin\Release\netcoreapp3.1\publish\</publishUrl>
<DeleteExistingFiles>True</DeleteExistingFiles>
</PropertyGroup>
</Project>
When I run dotnet.exe publish src\MyProject.Web.sln -p:PublishProfile=Properties\PublishProfiles\ProductionPublish.pubxml Release does not contain anything and publish happens on Debug folder (debug build). Whys does this happens and pubxml is ignored?
Update #1
Structure
src\MyProject\MyProject.csproj
src\MyProject.Utils\ect.Utils.csproj
src\MyProject.Web\MyProject.Web.csproj
src\MyProject.Web.sln
and the path of the pubxml
src\MyProject.Web\Properties\PublishProfiles\ProductionPublish.pubxml
You need the use following command:
dotnet build -c Release /p:DeployOnBuild=true /p:PublishProfile=FolderProfile
It's build, not publish.
Even if my FolderProfile's configuration is set to Release, I had to
include -c Release because otherwise dependent projects were built
with debug configuration.
Files not copied to target location if called without /p:DeployOnBuild=true.
Just the name FolderProfile -without extension- is enough for the
profile file. Or you can give the path
/p:PublishProfile=Properties\PublishProfiles\FolderProfile.pubxml
See Folder publish example from Microsoft Docs.
Found a solution on VS2022 and Core 6 to publish to an specific folder without indicating the output path on the CLI.
I created a profile called IISC
If you open that publish profile, you will see the PublishUrl property as follows
<PublishUrl>bin\Release\net6.0\publish\IISC</PublishUrl>
In My case I'm publishing to the solution folder bin\releas....\IISC
The trick is to add another propery called PublishDir
<PublishDir>bin\Release\net6.0\publish\IISC</PublishDir>
Now you can publish with this:
dotnet publish -c Release /p:PublishProfile=IISC
Find Bellow My complete Profile with and addition of an environment variable specific for this profile and and item group to exclude all the appsettings except for appsettings.json and appsettings.IISC.json
<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project>
<PropertyGroup>
<ASPNETCORE_ENVIRONMENT>iisc</ASPNETCORE_ENVIRONMENT>
<DeleteExistingFiles>true</DeleteExistingFiles>
<ExcludeApp_Data>false</ExcludeApp_Data>
<LaunchSiteAfterPublish>true</LaunchSiteAfterPublish>
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<PublishProvider>FileSystem</PublishProvider>
<PublishUrl>bin\Release\net6.0\publish\IISC</PublishUrl>
<PublishDir>bin\Release\net6.0\publish\IISC</PublishDir>
<WebPublishMethod>FileSystem</WebPublishMethod>
<SiteUrlToLaunchAfterPublish />
<TargetFramework>net6.0</TargetFramework>
<ProjectGuid>3e4c25a6-2051-4ccc-a518-645d46d120dd</ProjectGuid>
<SelfContained>false</SelfContained>
</PropertyGroup>
<ItemGroup>
<Content Update="appsettings.*.json">
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</Content>
<Content Update="appsettings.$(ASPNETCORE_ENVIRONMENT).json">
<CopyToPublishDirectory>Always</CopyToPublishDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<Folder Include="Properties\PublishProfiles\" />
</ItemGroup>
</Project>
I'm gonna answer for those who, like me, do want to use the publish command, because it's been designed to do so.
According to Options section on publish command, you can use the options configuration and output to solve your problem:
dotnet publish -c Release -o "<where you want>" -p:PublishProfile=<your profile name>
Note that where you want can be an absolute path and your profile name is only the name of profile, without "pubxml" and without the relative path (IF AND ONLY IF the profile is in "<project_folder>/Properties/PublishProfiles").
Related
I have a csproj file with nothing out of the ordinary
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<RootNamespace>AppService</RootNamespace>
<AssemblyName>AppService</AssemblyName>
</PropertyGroup>
<ItemGroup>
<PackageReference ..../>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Datastore\Datastore.csproj" />
</ItemGroup>
</Project>
Note the ProjectReference on the third line from the bottom of the file -
Both projects build fine - if I run dotnet build followed by dotnet run, everything is fine - however, if I try to run the code generated by the publish profile or even F5 - I get a CLR binding error:
I don't understand what is going on nor where to look. It's not an incorrect format error like many of the other questions.
I'm creating a C# app which I have build or as they call it "published" for linux-x64 following this XML in the csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<Configuration>release</Configuration>
<InvariantGlobalization>true</InvariantGlobalization>
<TargetFramework>net5.0</TargetFramework>
<PublishSingleFile>true</PublishSingleFile>
<SelfContained>true</SelfContained>
<RuntimeIdentifier>linux-x64</RuntimeIdentifier>
<PublishTrimmed>true</PublishTrimmed>
<PublishReadyToRun>true</PublishReadyToRun>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="mongocsharpdriver" Version="2.11.6" />
<PackageReference Include="MongoDB.Bson" Version="2.11.6" />
<PackageReference Include="MongoDB.Driver" Version="2.11.6" />
<PackageReference Include="MongoDB.Driver.Core" Version="2.11.6" />
<PackageReference Include="PCSC" Version="5.0.0" />
<PackageReference Include="PCSC.Iso7816" Version="5.0.0" />
</ItemGroup>
</Project>
I'm on Linux Ubuntu 20.04 .
I published the application using CLI to the folder bin/release etc etc. It ran just fine when I tested it. Now, for the main branch, I deleted all code. Moved the directory release up in the main directory, and pushed it to GIT.
Whenever you try to run it now, it gives the following error:
./Appname: relocation error: ./Appname: symbol pthread_attr_init version GLIBC_2.2.5 not defined in file libpthread.so.0 with link time reference
As I'm not a native C# developer and still learning, I have absolutely no idea what this is about, except it apparently has something to do with me moving the directory (I quess?)
Does anyone know what this error is or where it comes from, how to fix it, and how to prevent in the future? As I would like to be able to publish an application without errors.
solved
I Found the answer. There is another directory within the build directory called "publish" which contains the working executable. In other words. The exe is in the folder release/net5.0/linux-x64/publish instead of release/net5.0/linux-x64. When I run the executable from that directory, everything works just fine. For other newbies: It is in the folder release because my XML project file has a Configuration field set to release. It is in the folder Debug by default.
I have a .Net Core 3 console application that i'm trying to publish as a self contained single executable. I've been able to do this in the past but to my suprise it no longer works. The project structure is a console application with two assemblies, all in Core 3.
If i use dotnet publish -r win-x64 -c Release /p:PublishSingleFile=true /p:PublishTrimmed=true i expect the output to be a single executable of several mb's in size. However the publish folder contains the executable (few hundred kb) and a .dll file together with .cache files and the pdb.
The config for my console app is as follows:
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
<LangVersion>latest</LangVersion>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<Nullable>enable</Nullable>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<PublishSingleFile>true</PublishSingleFile>
<PublishTrimmed>true</PublishTrimmed>
</PropertyGroup>
If i publish the app directly from Visual Studio i get the same results as above.
So my question boils down to: Why doesnt this configuration or publish statement result in a self contained single executable?
I can get my 3.1 console app to publish with the following:
<?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>
<Configuration>Release</Configuration>
<Platform>Any CPU</Platform>
<PublishDir>..\..\Binaries\</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<PublishSingleFile>True</PublishSingleFile>
<PublishReadyToRun>False</PublishReadyToRun>
<DebugType>None</DebugType>
</PropertyGroup>
</Project>
If I set PublishReadyToRun to True (or add PublishTrimmed as True) it fails. Adding DebugType None prevents it publishing the pdb file for the exe.
UPDATE: removing the SelfContained tag stops it creating the 'dotnetcoreapp3.1' folder.
According to the command line release, I tested successfully. A single executable file was generated. If you have always failed to publish, I suggest you use VS to publish.The publishing process is as follows:
1.Right click on the project->publish
2.Change configuration
3.Save the configuration and click Publish
So I've made a self-contained release of a project with Visual Studio Code. The EXE is working on ubuntu and windows, but can't get it to work on os-x.
I'm using a simple data.json to store some data. The error that occurs on the os-x release, is that it can't find the correct path to data.json. I get this message:
Could not find file '/Users/User/data.json'.
That is not where I store the release or data.json. I store it in the root-directory of the project. Seems like the application is looking for the json-file in my system root directories. How do I fix this?
My XML csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp1.1</TargetFramework>
<RuntimeIdentifiers>win10-x64;osx.10.11-x64;ubuntu.16.10-x64</RuntimeIdentifiers>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.json" Version="10.0.3" />
</ItemGroup>
</Project>
I have the following configuration in DevLocalPublish.pubxml:
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WebPublishMethod>FileSystem</WebPublishMethod>
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<SiteUrlToLaunchAfterPublish />
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
<ExcludeApp_Data>False</ExcludeApp_Data>
<publishUrl>..\DevLocalPublish\</publishUrl>
<DeleteExistingFiles>True</DeleteExistingFiles>
<ExcludeGeneratedDebugSymbol>false</ExcludeGeneratedDebugSymbol>
</PropertyGroup>
It works perfectly when I export through Visual Studio. The pdb files get exported to ..\DevLocalPublish\bin as expected. However, when I run this from msbuild, it doesn't work correctly. Here's the target I created:
<Target Name="PublishDevLocally">
<MSBuild Projects="KepsPortalMvc\KepsPortalMvc.csproj" Targets="Clean;Rebuild" Properties="_DebugSymbolsProduced=true;BuildProjectReferences=true;Configuration=Release;Platform=Any CPU;DeployOnBuild=true;PublishProfile=DevLocalPublish;ExcludeGeneratedDebugSymbol=false;OutputPath=..\DevLocalPublish"/>
</Target>
I'm testing it with the following command:
msbuild direct.proj /t:PublishDevLocally
Everything else exports correctly. It's just the pdbs that aren't being published correctly. I've checked the bin folder in the project, and the pdbs are there, so the compiler is generated.
What am I doing wrong?
Edit: I've checked the obj\Release\Package\PackageTmp directory. I was able to get the pdb for the web project by adding the _DebugSymbolsProduced=true flag. However, it's not copying the pdbs of any of the referenced projects. I've uploaded PublishDevLocally to reflect my changes.
Turns out I needed to add the property DebugSymbols=true; The final target is
<Target Name="PublishDevLocally">
<MSBuild Projects="KepsPortalMvc\KepsPortalMvc.csproj" Targets="Clean;Rebuild" Properties="DebugSymbols=true;BuildProjectReferences=true;Configuration=Release;Platform=Any CPU;DeployOnBuild=true;PublishProfile=DevLocalPublish;OutputPath=..\DevLocalPublish"/>
</Target>