0

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 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Hi, thanks for your input. I am quite confused about all the reported errors in e.g. SessionModel.cs, since the application builds fine, when I build it "normally" through Visual Studio. It seems to be a ClickOnce problem only...
@Noceo, Yes, you can also create a new blank project to test this issue. But since I could not reproduce those two error on my side, I could not give a directly answer for this issue. Or you can provide a sample to reproduce sample or steps, then I will keep follow it.
While you might not be able to tell me exactly what the problem is, you did actually tell me, what the problem is not. So you have been very helpful :-). I am still stuck on exactly what is causing the problem, but I will update my question, if I find something significant.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.