How to change the output name of an executable built by Visual Studio
Asked Answered
B

8

140

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'

Broads answered 3/2, 2015 at 14:16 Comment(3)
msdn.microsoft.com/EN-US/library/ms247046(v=VS.120,d=hv.2).aspxUhf
@skrrgwasme - Not quite, Kiran's asking how to change the name of the output from a VS project.Ancalin
If like me you wanted to change the output file name without changing the assembly name, see stackoverflow.com/a/44188341.Jeaz
A
188
  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"
Anemic answered 3/2, 2015 at 14:20 Comment(3)
@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.Anemic
Can I change Exe file name based on command line arguments during pre-build or post-build events?Pentylenetetrazol
If like me you wanted to change the output file name without changing the assembly name, see stackoverflow.com/a/44188341.Jeaz
J
41

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>
Jeaz answered 25/5, 2017 at 19:24 Comment(9)
this worked like a charm. Except now debug process cannot find the executable anymore ..Reliable
@BorisCallens Huh, with new csproj debugging works fine if you're targeting .NET Framework and doesn't work if you're targeting .NET Core. Guess we need to raise an issue. With old csproj (which is .NET Framework only) it doesn't work either. Which kind of csproj are you using?Jeaz
Issue for new csproj and .NET Core: github.com/dotnet/project-system/issues/2556Jeaz
Old csproj, .net 4.6.1. Will check the issue.Reliable
Correction: Issue is for old csproj too.Jeaz
This did not work for me. I get a build error that the exe cannot be found.Tombstone
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.Anzus
@Anzus <AssemblyName> works on .NET 6. Not sure about earlier versions.Indus
@EricEskildsen, perhaps I should have just specified .NET 5, that's what I tested it with and the issue I mentioned (and should have linked) wasn't fixed at that time.Anzus
C
25

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.

Capability answered 11/6, 2022 at 19:47 Comment(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=MyCustomExecutableNameCounterweigh
S
14

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.

Shelbashelbi answered 12/5, 2017 at 9:44 Comment(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)Aruabea
C
4

"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
Circus answered 11/3, 2021 at 9:34 Comment(1)
This is nice and clean, and avoids all the VS problems. I wanted to append a version number. This tried to rename my dll though, so I did copy $(OutDir)\projectname.exe $(OutDir)\projectname_1.0.exe /YInvolucrum
B
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'

Bullfighter answered 27/8, 2016 at 14:36 Comment(0)
S
0

For a UWP app, right-click on the solution in Solution Explorer and select Rename.

Scornful answered 2/10, 2023 at 8:58 Comment(0)
P
0

If this is a .NET Core app being published then this does the trick:

<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.

Prestonprestress answered 8/3, 2024 at 12:46 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.