更改 .csproj 中构建设置的程序集名称

Noc*_*ceo 3 c# msbuild clickonce

我有一个应用程序,我想通过命令行使用 ClickOnce 发布。我有测试版和现场版。应该允许同时安装两者,这意味着我需要更改其中一个版本的汇编名称(最好还有产品名称)。我想在构建设置中执行此操作。

我已经设法进行了一些构建设置,效果很好,但我无法弄清楚如何更改程序集和产品名称,仅针对其中之一。

我已将以下代码添加到我的.csproj文件中,我使用命令msbuild /target:Test或调用该代码msbuild /target:Live但是我在哪里实施组件和产品名称更改呢?

<PropertyGroup>
  <ProjLocation>$(ProjectDir)</ProjLocation>
  <ProjLocationReleaseDir>$(ProjLocation)\bin\Debug</ProjLocationReleaseDir>
  <ProjPublishLocation>$(ProjLocationReleaseDir)\app.publish</ProjPublishLocation>
  <DeploymentFolder>C:\MyProjects\Software\Publish\</DeploymentFolder>
</PropertyGroup>

<!-- Build settings for live version -->
<Target Name="Live" DependsOnTargets="Clean">

  <MSBuild Projects="$(ProjLocation)\$(ProjectName).csproj"
    Properties="$(DefaultBuildProperties)"
    Targets="Publish"/>

  <ItemGroup>
    <SetupFiles Include="$(ProjPublishLocation)\*.*"/>
    <UpdateFiles Include="$(ProjPublishLocation)\Application Files\**\*.*"/>
  </ItemGroup>


  <Copy SourceFiles="@(SetupFiles)" DestinationFolder="$(DeploymentFolder)\Live\" />
  <Copy SourceFiles="@(UpdateFiles)" DestinationFolder="$(DeploymentFolder)\Live\Application Files\%(RecursiveDir)"/>
</Target>

<!-- Build settings for test version -->
<Target Name="Test" DependsOnTargets="Clean">

  <MSBuild Projects="$(ProjLocation)\$(ProjectName).csproj"
    Properties="$(DefaultBuildProperties)"
    Targets="Publish"/>

  <ItemGroup>
    <SetupFiles Include="$(ProjPublishLocation)\*.*"/>
    <UpdateFiles Include="$(ProjPublishLocation)\Application Files\**\*.*"/>
  </ItemGroup>


  <Copy SourceFiles="@(SetupFiles)" DestinationFolder="$(DeploymentFolder)\Public Test\" />
  <Copy SourceFiles="@(UpdateFiles)" DestinationFolder="$(DeploymentFolder)\Public Test\Application Files\%(RecursiveDir)"/>
</Target>
Run Code Online (Sandbox Code Playgroud)

小智 6

您可以将“AssemblyName”属性添加到 PropertyGroup。像这样:

<PropertyGroup>
  <AssemblyName>YourAppName</AssemblyName>
</PropertyGroup>
Run Code Online (Sandbox Code Playgroud)

或者您可以使用 MSBuild 命令行开关。像这样 :

msbuild /property:AssemblyName=YourAppName
Run Code Online (Sandbox Code Playgroud)