MSBuild:如何覆盖输出文件名与程序集名称不同?

时间:2022-07-28 14:01:08

I have 2 C# projects in my solution, both of them DLLs:

我的解决方案中有2个C#项目,它们都是DLL:

  • MyApp.UI.WPF.csproj
  • MyApp.UI.WinForms.csproj

My setup process guarantees that only one of them will be installed at any given time. Whichever that might be, it will be picked up by the MyApp.exe bootstrapper when user runs the application.

我的设置过程保证在任何给定时间只安装其中一个。无论哪个,当用户运行应用程序时,MyApp.exe引导程序都会选择它。

Since both DLLs contain the same entry point, I'd like to keep the bootstrapper generic:

由于两个DLL都包含相同的入口点,因此我想保持引导程序的通用性:

class Bootstrapper
{
    static void Main()
    {
        var asm = Assembly.Load("MyApp.UI");

        // Execute the UI entry point here.
    }
}

This means I have to give both DLLs the same Assembly Name in project options: "MyApp.UI". The problem is that MSBuild uses the Assembly Name as the output name which poses a conflict for me.

这意味着我必须在项目选项中为两个DLL提供相同的程序集名称:“MyApp.UI”。问题是MSBuild使用程序集名称作为输出名称,这给我带来了冲突。

Is it possible to convince MSBuild to use a different filename instead, e.g. the project name?

是否有可能说服MSBuild使用不同的文件名,例如项目名称?

2 个解决方案

#1


You could add a <PostBuildEvent> to your build to rename your output assemblies to a common name.

您可以将 添加到构建中,以将输出程序集重命名为公用名。

#2


This would be a function of the CoreCompile task, you would have to override it to modify the /out switch on csc. This is not recommended practice but would achieve your goal.

这将是CoreCompile任务的一个功能,您必须覆盖它以修改csc上的/ out开关。这不是推荐的做法,但会实现您的目标。

#1


You could add a <PostBuildEvent> to your build to rename your output assemblies to a common name.

您可以将 添加到构建中,以将输出程序集重命名为公用名。

#2


This would be a function of the CoreCompile task, you would have to override it to modify the /out switch on csc. This is not recommended practice but would achieve your goal.

这将是CoreCompile任务的一个功能,您必须覆盖它以修改csc上的/ out开关。这不是推荐的做法,但会实现您的目标。