0
votes

I am trying to configure an MSBuild target, in my Project.csproj file. The target, called "Test" is called with the following command:

msbuild.exe /target:Test

However, I cannot figure out how to change the AssemblyName (original assembly name is MyProject), for this target. My code looks like this:

<Target Name="Test">
  <PropertyGroup>
    <PublishUrl>D:\PublishLocation\ClickOnce Setup\</PublishUrl>
  </PropertyGroup>
  <MSBuild Projects="$(ProjLocation)\$(ProjectName).csproj" Properties="ProductName=$(ProductName) (Test); AssemblyName=MyProjectTest; PublishUrl=$(PublishUrl)" Targets="Publish" />
  <ItemGroup>
    <SetupFiles Include="$(ProjPublishLocation)\*.*" />
    <UpdateFiles Include="$(ProjPublishLocation)\Application Files\**\*.*" />
  </ItemGroup>
  <Copy SourceFiles="@(SetupFiles)" DestinationFolder="D:\PublishLocation\ClickOnce Setup\" />
  <Copy SourceFiles="@(UpdateFiles)" DestinationFolder="D:\PublishLocation\ClickOnce Setup\Application Files\%(RecursiveDir)" />
</Target>

If I remove the AssemblyName=MyProjectTest; from the code, it works fine. If I run it as above, I get the following error:

"C:\Users\...\MyProject\MyProject.csproj" (Test target) (1) -> "C:\Users\...\MyProject\MyProject.csproj" (Publish target) (1:2 ) ->

(CoreCompile target) ->
Models\SessionModel.cs(207,51): error CS1528: Expected ; or = (cannot specify constructor arguments in declaration) [ C:\Users\...\MyProject\MyProject.csproj]

(...and a lot more, which is more or less the same)

UPDATE

I found some more, perhaps more interesting, warnings in the build output:

"C:\Users\...\MyProject\MyProject.csproj" (Fast target) (1) -> "C:\Users\...\MyProject.csproj" (Publish target) (1:2 ) -> (ResolveAssemblyReferences target) ->
C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(1820,5): warning MSB3277: Found conflicts between different versions of the same dependent assembly that could not be resolved. These reference conflicts a re listed in the build log when log verbosity is set to detailed. [C:\Users\...\MyProject\MyProject.csproj]

It might be worth mentioning, that I have older versions published in the publish location, in which the assembly name was not changed. Can this cause the conflict I see...?

2

2 Answers

1
votes

Change AssemblyName via MSBuild Target

According to your Test target and another post, I have created a sample app to test this issue with following scripts and MSBuild command line msbuild.exe /target:Test:

  <PropertyGroup>
    <ProjLocation>$(ProjectDir)</ProjLocation>
    <ProjLocationReleaseDir>$(ProjLocation)\bin\Debug</ProjLocationReleaseDir>
    <ProjPublishLocation>$(ProjLocationReleaseDir)\app.publish</ProjPublishLocation>
    <DeploymentFolder>D:\PublishFolder\Test\</DeploymentFolder>
  </PropertyGroup>

  <Target Name="Test" DependsOnTargets="Clean">
    <MSBuild Projects="$(ProjLocation)\$(ProjectName).csproj" Properties="ProductName=$(ProductName) (Test); AssemblyName=MyProjectTest; PublishUrl=$(PublishUrl)" 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>

It works fine without any issue, and assembly name was also changed:

enter image description here

So this issue should be more related to the error CS1528 in the SessionModel.cs file and warning MSB3277. To resolve the CS1528 error, you can check the document Compiler Error CS1528 for some more details.

And for the warning MSB3277, you can change the "MSBuild project build output verbosity" to "Detailed" to check the reference conflicts and resolve this conflicts. you can see this thread for some details.

Hope this helps.

0
votes

It turns out the problem was, that I had included System.net.http.dll as a file in my project. This was set to Content as build actions. When I changed it to Embedded resource, it started working.