简体   繁体   中英

WPF project mutiple and different builds under VS2015 express

I have a WPF project under VS2015 express (eventually I can switch to VS2017) for which I wish to have several builds that differs in :

  • icon file
  • variable value
  • exe names
  • (maybe other things, like the language but I can deal with variable values I guess)

For example :

  • one will build MyProject_Soc1_Val1.exe that will have file.Soc1.ico as icon file and MyVariable = Val1
  • another one build MyProject_Soc2_Val2.exe with file.Soc2.ico and MyVariable=Val2
  • ...

Ideally, I'd like if all can be built in one click

Is that possible ? And how ?

Thx

Ok, I looked at MSbuild and I kinda partly solved my problem in these ways :

First I created one project configuration for each case I wish to build. Then...

Ico and SplacshScreen

I closed the VS project and changed the .csproj file this way :

  <PropertyGroup>
    <ApplicationIcon Condition=" '$(Configuration)' == 'Release' ">LogoMini.Soc1.ico</ApplicationIcon>
    <ApplicationIcon Condition=" '$(Configuration)' == 'Debug' ">LogoMini.Soc1.ico</ApplicationIcon>
    <ApplicationIcon Condition=" '$(Configuration)' == 'Soc2' ">LogoMini.Soc2.ico</ApplicationIcon>
  </PropertyGroup>
  [...]
  <ItemGroup>
    <SplashScreen Condition=" '$(Configuration)' == 'Debug' " Include="Images\SplahScreen.Soc1.png" />
    <SplashScreen Condition=" '$(Configuration)' == 'Release' " Include="Images\SplahScreen.Soc1.png" />
    <SplashScreen Condition=" '$(Configuration)' == 'Soc2' " Include="Images\SplahScreen.Soc2.png" />
  </ItemGroup>

It kinda work, but :

  • The icon won't necessarly be the good one when I launch the exe ... but I think that is because Windows keep it in cache. So should be ok
  • I'm not really comfortable with it because now the informations I get, for example in VS>project>properties>Build>Icon file are not correct.

Variables

I added in My Projects > Properties > Build > Conditional compilation symbols the symbol SOCi (for each project configuration i).

And in the C# code :

int MyVar;
#if SOC1
    MyVar = 1;
#elif SOC2
    MyVar = 2;
#endif

That is fine I guess.

For the rest

  • I finally did not change the exe name, but I guess I could change .csproj by adding a Condition on AssemblyName
  • I could not compile 2 configurations at the same time, but it's not really a big deal

I will wait a while before marking this as the solution in case someone as a comment or correction to do.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM