Reputation: 1891
I want to change name of executable file. Like suppose my project name is "SampleDemo" It will create executable file Like 'SampleDemo.exe' but I want to rename it to 'Demo.exe'
Upvotes: 146
Views: 155825
Reputation: 1567
For projects targeting .NET Core and onward, it is possible to perform a custom action after the application as been published
:
<Target Name="RenameOutputExecutable" AfterTargets="Publish">
<Move SourceFiles="$(PublishDir)$(AssemblyName)" DestinationFiles="$(PublishDir)new-name-here"/>
<Message Text="Renamed executable file from $(PublishDir)$(AssemblyName) to $(PublishDir)new-name-here" Importance="high"/>
</Target>
This will only take effect when publishing.
Note that you might need to add the file extension .exe
, if the file is not found.
Upvotes: 1
Reputation: 8364
To change the output file name without modifying the assembly name, you can include the following line in the primary <PropertyGroup>
of your .csproj file:
<TargetName>Desired output name without extension</TargetName>
Upvotes: 47
Reputation: 1097
For a UWP app, right-click on the solution in Solution Explorer and select Rename.
Upvotes: 0
Reputation: 49
"Post-build event command line" in Build Events tab, would be an option. You can use:
copy $(TargetPath) $(TargetDir)demo.exe /Y
or
ren $(TargetPath) $(TargetDir)demo.exe /Y
Upvotes: 4
Reputation: 934
For me none of the answers worked in net6.
In my csproj
file:
<PropertyGroup>
<AssemblyName>MyCustomExecutableName</AssemblyName>
</PropertyGroup>
Tested in Net6, Windows. Using VS Code and buiding with dotnet run
.
This will change both the executable name and the dll file name.
Upvotes: 39
Reputation: 141
By MsBuild:
<Target Name="Rename" AfterTargets="AfterBuild">
<Move SourceFiles="$(OUTDIR)\Application1.exe" DestinationFiles="$(OUTDIR)\ApplicationNew.exe" />
<Message Text="Renamed executable file." Importance="high" />
</Target>
Change ApplicationName is not best way. For example if you used wpf resources, full path contains ApplicationName and after renaming executable file you need to change all full pathes in out application
<ResourceDictionary Source="pack://application:,,,/Application1;component/Themes/CustomStyles.xaml"/>
In this situation I used msbuild.
Upvotes: 14
Reputation: 1321
Double Click 'My Project'
Click 'Package Manifest...'
Click 'Application'
Under 'Display Name' fill in the name you want your exe to be called.
In your case it would be: 'Demo' since you want the project name 'SampleDemo' to have an output exe named 'Demo'
Upvotes: 0
Reputation: 11587
Upvotes: 197