Ability to set package name #74

Open
opened 2026-01-29 16:28:38 +00:00 by claunia · 3 comments
Owner

Originally created by @leoshusar on GitHub (Apr 5, 2020).

Hello, I am currently trying to package my app for linux and I have problems with naming.
My assembly name was with underscore -> debian does not allow underscores in names.
I changed it to dash -> I was having problems with building.
Lastly I changed my assembly name and namespace to AppName (as I found that this is the right naming convention) but linux does not allow uppercase letters in names too.

I would like to specify my own package name (name like app-name) or at least convert it to lowercase naturally (appname).

Or did I miss something and this ability is already there?

Originally created by @leoshusar on GitHub (Apr 5, 2020). Hello, I am currently trying to package my app for linux and I have problems with naming. My assembly name was with underscore -> debian does not allow underscores in names. I changed it to dash -> I was having problems with building. Lastly I changed my assembly name and namespace to AppName (as I found that this is the right naming convention) but linux does not allow uppercase letters in names too. I would like to specify my own package name (name like app-name) or at least convert it to lowercase naturally (appname). Or did I miss something and this ability is already there?
Author
Owner

@joshd-7 commented on GitHub (Apr 9, 2020):

I just ran into this as well. After doing a fair amount of digging in the code and testing there's a few settings you can make in your .csproj

To change the debian package name: (Debian naming standard in example, underscores and periods are ok in this one)
<PackageName>debian-package-name_0.1.0-1_amd64</PackageName>
Output ex: debian-package-name_0.1.0-1_amd64.deb

To change the "Package" variable in the control file of the debian package: (Important that this doesn't have underscores, periods or upper case)
<PackagePrefix>project-name</PackagePrefix>

Here's how you can verify the changes if you need.
Unpack the debian in a folder with dpkg -e debian-package-name_0.1.0-1_amd64.deb
Open the control file and verify the value assigned is correct Package=project-name

Here's some of the other properties I set within the .csproj to help populate the other Debian files.
<PropertyGroup>
<DebPackageArchitecture>amd64</DebPackageArchitecture>
<PackagePrefix>project-name</PackagePrefix>
<PackageName>debian-package-name_0.1.0-1_amd64</PackageName>
<Version>0.1.0-1</Version>
<Authors></Authors>
<Company>CompanyName</Company>
<Product>ProductName</Product>
</PropertyGroup>

There might be better ways of doing this, but this is what I got to work for me. I was able to leave my project and assembly name pascal case with periods in it.

@joshd-7 commented on GitHub (Apr 9, 2020): I just ran into this as well. After doing a fair amount of digging in the code and testing there's a few settings you can make in your .csproj To change the debian package name: (Debian naming standard in example, underscores and periods are ok in this one) `<PackageName>debian-package-name_0.1.0-1_amd64</PackageName>` Output ex: debian-package-name_0.1.0-1_amd64.deb To change the "Package" variable in the control file of the debian package: (Important that this doesn't have underscores, periods or upper case) `<PackagePrefix>project-name</PackagePrefix>` Here's how you can verify the changes if you need. Unpack the debian in a folder with `dpkg -e debian-package-name_0.1.0-1_amd64.deb` Open the control file and verify the value assigned is correct `Package=project-name` Here's some of the other properties I set within the .csproj to help populate the other Debian files. `<PropertyGroup>` ` <DebPackageArchitecture>amd64</DebPackageArchitecture>` ` <PackagePrefix>project-name</PackagePrefix>` ` <PackageName>debian-package-name_0.1.0-1_amd64</PackageName>` ` <Version>0.1.0-1</Version>` ` <Authors></Authors>` ` <Company>CompanyName</Company>` ` <Product>ProductName</Product>` `</PropertyGroup>` There might be better ways of doing this, but this is what I got to work for me. I was able to leave my project and assembly name pascal case with periods in it.
Author
Owner

@leoshusar commented on GitHub (Apr 9, 2020):

Thank you!
I've made some tweaks to it, you might find it useful:

<PropertyGroup>
    <AssemblyName>MyAwesomeProject</AssemblyName>
    <Version>0.1.0-1</Version>
    <PackagePrefix>$([System.Text.RegularExpressions.Regex]::Replace($(AssemblyName), "\B[A-Z]", "-$0").ToLower())</PackagePrefix>
    <DebPackageArchitecture Condition="$(RuntimeIdentifier.Contains('x64'))">amd64</DebPackageArchitecture>
    <DebPackageArchitecture Condition="$(RuntimeIdentifier.Contains('x86'))">i386</DebPackageArchitecture>
    <DebPackageArchitecture Condition="$(RuntimeIdentifier.Contains('arm'))">armhf</DebPackageArchitecture>
    <PackageName>$(PackagePrefix)_$(Version)_$(DebPackageArchitecture)</PackageName>
</PropertyGroup>

What it does is it generates PackagePrefix from AssemblyName - adds a dash before every capital letter and makes it lowercase.
Then it selects DebPackageArchitecture using your RuntimeIdentifier (-r switch).
Finally it makes PackageName as PackagePrefix_Version_DebPackageArchitecture.

Finally all you have to do is for example dotnet deb -c Release -r linux-x64 and it will generate file named my-awesome-project_0.1.0-1_amd64.deb.

There will surely also be a way to add this to a separate file and then just write some single line Include in your .csproj, but this is enough for me now.

EDIT: the only problem now is that installed binary file is still PascalCase.
EDIT2: Solved! This targets renames binary file in OUTDIR (probably not necessary), then it renames binary file in OUTDIR\publish (this one is important) and finally it sets AppHost name and this is the name of the symlink in /usr/local/bin.

<Project>
    ...
  <Target Name="RenameAfterBuild" AfterTargets="AfterBuild" Condition="$(RuntimeIdentifier.Contains('linux'))">
    <Move SourceFiles="$(OUTDIR)\$(AssemblyName)" DestinationFiles="$(OUTDIR)\$(PackagePrefix)" />
    <Message Text="Renamed linux binary file." Importance="high" />
  </Target>
  <Target Name="RenameBeforePublish" BeforeTargets="CreatePackageProperties" Condition="$(RuntimeIdentifier.Contains('linux'))">
    <Move SourceFiles="$(OUTDIR)publish\$(AssemblyName)" DestinationFiles="$(OUTDIR)publish\$(PackagePrefix)" />
    <Message Text="Renamed linux binary file." Importance="high" />
  </Target>
  <Target Name="SetAppHostName" AfterTargets="CreatePackageProperties" Condition="$(RuntimeIdentifier.Contains('linux'))">
    <PropertyGroup>
      <AppHost Condition="'$(SymlinkAppHostInBin)' == 'true'">$(PackagePrefix)$(_NativeExecutableExtension)</AppHost>
    </PropertyGroup>
  </Target>
</Project>

EDIT3: If you put everything into Directory.Build.targets file, it will automatically pick it up and you don't have to edit your .csproj file. All you need is then copy that file into your another project and you're ready to go.

@leoshusar commented on GitHub (Apr 9, 2020): Thank you! I've made some tweaks to it, you might find it useful: ``` <PropertyGroup> <AssemblyName>MyAwesomeProject</AssemblyName> <Version>0.1.0-1</Version> <PackagePrefix>$([System.Text.RegularExpressions.Regex]::Replace($(AssemblyName), "\B[A-Z]", "-$0").ToLower())</PackagePrefix> <DebPackageArchitecture Condition="$(RuntimeIdentifier.Contains('x64'))">amd64</DebPackageArchitecture> <DebPackageArchitecture Condition="$(RuntimeIdentifier.Contains('x86'))">i386</DebPackageArchitecture> <DebPackageArchitecture Condition="$(RuntimeIdentifier.Contains('arm'))">armhf</DebPackageArchitecture> <PackageName>$(PackagePrefix)_$(Version)_$(DebPackageArchitecture)</PackageName> </PropertyGroup> ``` What it does is it generates `PackagePrefix` from `AssemblyName` - adds a dash before every capital letter and makes it lowercase. Then it selects `DebPackageArchitecture` using your RuntimeIdentifier (-r switch). Finally it makes `PackageName` as `PackagePrefix_Version_DebPackageArchitecture`. Finally all you have to do is for example `dotnet deb -c Release -r linux-x64` and it will generate file named `my-awesome-project_0.1.0-1_amd64.deb`. There will surely also be a way to add this to a separate file and then just write some single line Include in your .csproj, but this is enough for me now. EDIT: the only problem now is that installed binary file is still PascalCase. EDIT2: Solved! This targets renames binary file in OUTDIR (probably not necessary), then it renames binary file in OUTDIR\publish (this one is important) and finally it sets AppHost name and this is the name of the symlink in /usr/local/bin. ``` <Project> ... <Target Name="RenameAfterBuild" AfterTargets="AfterBuild" Condition="$(RuntimeIdentifier.Contains('linux'))"> <Move SourceFiles="$(OUTDIR)\$(AssemblyName)" DestinationFiles="$(OUTDIR)\$(PackagePrefix)" /> <Message Text="Renamed linux binary file." Importance="high" /> </Target> <Target Name="RenameBeforePublish" BeforeTargets="CreatePackageProperties" Condition="$(RuntimeIdentifier.Contains('linux'))"> <Move SourceFiles="$(OUTDIR)publish\$(AssemblyName)" DestinationFiles="$(OUTDIR)publish\$(PackagePrefix)" /> <Message Text="Renamed linux binary file." Importance="high" /> </Target> <Target Name="SetAppHostName" AfterTargets="CreatePackageProperties" Condition="$(RuntimeIdentifier.Contains('linux'))"> <PropertyGroup> <AppHost Condition="'$(SymlinkAppHostInBin)' == 'true'">$(PackagePrefix)$(_NativeExecutableExtension)</AppHost> </PropertyGroup> </Target> </Project> ``` EDIT3: If you put everything into `Directory.Build.targets` file, it will automatically pick it up and you don't have to edit your .csproj file. All you need is then copy that file into your another project and you're ready to go.
Author
Owner

@joshd-7 commented on GitHub (Apr 10, 2020):

Great additions! That was the next thing I was going to look into for improving it. Thanks a bunch!

@joshd-7 commented on GitHub (Apr 10, 2020): Great additions! That was the next thing I was going to look into for improving it. Thanks a bunch!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/dotnet-packaging#74