121

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'

3

6 Answers 6

171
  1. Open the Project Properties in Visual Studio (right click on project in Solution Explorer and select "Properties" from popup menu)
  2. On the "Application" tab of the properties window, change the "Assembly name"
4
  • @KiranDesai I think you are editing the AssemblyInfo.cs file. You need to edit the project properties instead. I've clarified this in my answer.
    – Ross McNab
    Feb 3, 2015 at 14:50
  • Thanks for clarification, your solution works properly. Feb 4, 2015 at 5:33
  • 1
    Can I change Exe file name based on command line arguments during pre-build or post-build events? Mar 20, 2016 at 13:47
  • 3
    If like me you wanted to change the output file name without changing the assembly name, see stackoverflow.com/a/44188341.
    – jnm2
    May 25, 2017 at 19:24
37

If like me you wanted to change the output file name without changing the assembly name, put this like in your .csproj's main <PropertyGroup>:

    <TargetName>Desired output name without extension</TargetName>
9
  • 5
    this worked like a charm. Except now debug process cannot find the executable anymore .. Jul 4, 2017 at 12:01
  • 1
    Correction: Issue is for old csproj too.
    – jnm2
    Jul 5, 2017 at 12:20
  • 2
    This did not work for me. I get a build error that the exe cannot be found. Jan 15, 2019 at 20:07
  • 1
    For anyone reading this for .Net 5+ - this will only change the *.dll and *.pdb file names, it won't change the *.exe name AND the application will still look for its original name.dll. I.e. if your project is named "Test" but you put <TargetName>Change</TargetName> you will see the following files in the build output: Test.exe, Change.dll and Change.pdb (depending on settings). So, building or running the application (Test.exe) will fail with The application to execute does not exist: (path to dir)\Test.dll. Yes, there is an ancient open issue for this.
    – Tessaract
    Feb 24, 2022 at 12:23
  • 1
    @Tessaract <AssemblyName> works on .NET 6. Not sure about earlier versions. May 9, 2022 at 19:35
12

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.

1
  • 1
    This is nice because if you replace Move with Copy, debugging will still work (the other answer's problem is not fixed for me as of VS2017)
    – Kolichikov
    Mar 28, 2019 at 18:09
6

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.

1
  • 1
    Without touching the csproj file, the output assembly name can also be specified by passing the MSBuild property via the command line: /p:AssemblyName=MyCustomExecutableName
    – oli
    Jul 19, 2022 at 15:17
2

"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
0

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'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.