Creating a Visual Studio project with various platforms through MSBuild

I have 3 projects with configuration:

  • Project A: Debugging | AnyCPU, Release | AnyCPU
  • Project B: Debugging | AnyCPU, Release | AnyCPU
  • Project C: Debugging | x86 debugging | x64 edition | x86 release | x64

Project C has B in dependencies, and B has dependencies A. (A <-B <-C)

I use the * .bat file to create it from the command line:

msbuild A.csproj /target:Build /property:Configuration=Debug;Platform=AnyCPU /verbosity:minimal msbuild A.csproj /target:Build /property:Configuration=Release;Platform=AnyCPU /verbosity:minimal<br/> msbuild B.csproj /target:Build /property:Configuration=Debug;Platform=AnyCPU /verbosity:minimal msbuild B.csproj /target:Build /property:Configuration=Release;Platform=AnyCPU /verbosity:minimal msbuild C.csproj /target:Build /property:Configuration=Debug;Platform=x86 /verbosity:minimal msbuild C.csproj /target:Build /property:Configuration=Release;Platform=x86 /verbosity:minimal msbuild C.csproj /target:Build /property:Configuration=Debug;Platform=x64 /verbosity:minimal msbuild C.csproj /target:Build /property:Configuration=Release;Platform=x64 /verbosity:minimal 

And get the error:

C: \ Windows \ Microsoft.NET \ Framework64 \ v4.0.30319 \ Microsoft.Common.targets (609.5): error: the OutputPath property was not set for the project 'A.csproj'. Make sure you specify the correct combination of configuration and platform for this project. Configuration = 'Debug' Platform = 'x86'. You can see this message because you are trying to create a project without a solution file and you specified a configuration or platform other than the default that does not exist for this project. [A.csproj] C: \ Windows \ Microsoft.NET \ Framework64 \ v4.0.30319 \ Microsoft.Common.targets (609.5): error: the OutputPath property was not set for the "B.csproj" project. Make sure you specify the correct combination of configuration and platform for this project. Configuration = 'Debug' Platform = 'x86'. You can see this message because you are trying to create a project without a solution file and you specified a configuration or platform other than the default that does not exist for this project. [B.csproj]

+4
source share
3 answers

I found a solution for my problem. Usage Select an item in the * .csproj file to discover the building through Visual Studio or through MSBuild and use the link (instead of ProjectReference) for MSBuild.

 <Choose> <When Condition="'$(BuildingInsideVisualStudio)' == 'true'"> <ItemGroup> <ProjectReference Include="A.csproj"> <Project>{AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA}</Project> <Name>A</Name> <Private>True</Private> </ProjectReference> <ProjectReference Include="B.csproj"> <Project>{BBBBBBBB-BBBB-BBBB-BBBB-BBBBBBBBBBBB}</Project> <Name>B</Name> <Private>True</Private> </ProjectReference> </ItemGroup> </When> <Otherwise> <ItemGroup> <Reference Include="A, Version=1.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxxx, processorArchitecture=MSIL"> <HintPath>A.dll</HintPath> <Private>True</Private> </Reference> <Reference Include="B, Version=1.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxxx, processorArchitecture=MSIL"> <HintPath>B.dll</HintPath> <Private>True</Private> </Reference> </ItemGroup> </Otherwise> </Choose> 
+5
source

You can do this if you define custom assembly configurations in the solution file.

Open the solution in Visual Studio, then open Configuration Manager for the solution. The Active Solutions drop-down list will have the <New...> option, which will allow you to create x86 and x64 platforms for the solution. After you create them, select each of them in the same drop-down list and make sure that you have Any CPU for your projects A and B in the list and that project C has x86 or x64, respectively. Also make sure the Build checkbox is selected.

Now switch the Active solution configuration to Release and define these additional platforms in the same way.

After that, you can build all 3 projects that define only the solution file on the MSbuild command line:

 msbuild ABC.sln /target:Build /property:Configuration=Debug;Platform=x86 /verbosity:minimal msbuild ABC.sln /target:Build /property:Configuration=Release;Platform=x86 /verbosity:minimal msbuild ABC.sln /target:Build /property:Configuration=Debug;Platform=x64 /verbosity:minimal msbuild ABC.sln /target:Build /property:Configuration=Release;Platform=x64 /verbosity:minimal 
+3
source

You can try building a project with devenv.exe from the command line. I think that you will not have the problems that you experienced, but I remember something about this version of the assembly to be obsolete, and sometimes it was hung for no reason. I wrote this as one of the options, simply because the other two are also not suitable for me.

0
source

Source: https://habr.com/ru/post/1433325/


All Articles