我想更改可执行文件的名称。比如假设我的项目名是“ SampleDemo”,它会创建可执行文件,比如“ SampleDemo.exe”,但是我想把它重命名为“ Demo.exe”
Double Click 'My Project'
点击“包裹清单...”
按「申请」
在“显示名称”下填写您希望您的 exe 被调用的名称。
In your case it would be: 'Demo' since you want the project name 'SampleDemo' to have an output exe named 'Demo'
作者: MsBuild:
<Target Name="Rename" AfterTargets="AfterBuild"> <Move SourceFiles="$(OUTDIR)\Application1.exe" DestinationFiles="$(OUTDIR)\ApplicationNew.exe" /> <Message Text="Renamed executable file." Importance="high" /> </Target>
更改 ApplicationName 不是最佳方式。 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"/>
在这种情况下,我使用 msbuild。
如果您像我一样想要更改输出文件名 没有更改程序集名称,请将这样的代码放入您的。Csproj 的主要 <PropertyGroup>:
<PropertyGroup>
<TargetName>Desired output name without extension</TargetName>
“生成事件”选项卡中的“生成后事件命令行”将是一个选项。 你可使用:
copy $(TargetPath) $(TargetDir)demo.exe /Y
或者
ren $(TargetPath) $(TargetDir)demo.exe /Y
对我来说,在 net6中没有一个答案是有效的。
在我的 csproj文件中:
csproj
<PropertyGroup> <AssemblyName>MyCustomExecutableName</AssemblyName> </PropertyGroup>
在 Net6,Windows 中测试。使用 VS 代码和构建与 dotnet run。 这将同时更改可执行文件名和 dll 文件名。
dotnet run