简体   繁体   English

WPF项目多个版本以及VS2015 Express下的不同版本

[英]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 : 我在VS2015 Express下有一个WPF项目(最终我可以切换到VS2017),我希望拥有几个不同的版本:

  • icon file 图标文件
  • variable value 可变值
  • exe names exe名称
  • (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 一个将构建MyProject_Soc1_Val1.exe,它将具有file.Soc1.ico作为图标文件,并且MyVariable = Val1
  • another one build MyProject_Soc2_Val2.exe with file.Soc2.ico and MyVariable=Val2 另一个使用file.Soc2.ico和MyVariable = Val2构建MyProject_Soc2_Val2.exe
  • ... ...

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 : 好的,我查看了MSbuild,并通过以下方式部分解决了我的问题:

First I created one project configuration for each case I wish to build. 首先,我为要构建的每种情况创建了一个项目配置。 Then... 然后...

Ico and SplacshScreen Ico和SplacshScreen

I closed the VS project and changed the .csproj file this way : 我以这种方式关闭了VS项目并更改了.csproj文件:

  <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. 当我启动exe时,该图标不一定会是一个好的图标...但是我认为这是因为Windows将其保留在缓存中。 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. 我对此不太满意,因为现在我得到的信息(例如,VS> project> properties> Build> Icon文件中的信息不正确)。

Variables 变量

I added in My Projects > Properties > Build > Conditional compilation symbols the symbol SOCi (for each project configuration i). 我在“我的项目”>“属性”>“构建”>“条件编译”符号中添加了符号SOCi(针对每个项目配置i)。

And in the C# code : 并在C#代码中:

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 我终于没有更改exe名称,但是我想我可以通过在AssemblyName上添加条件来更改.csproj
  • I could not compile 2 configurations at the same time, but it's not really a big deal 我无法同时编译2个配置,但这并不是什么大不了的事情

I will wait a while before marking this as the solution in case someone as a comment or correction to do. 我将稍等片刻,然后将其标记为解决方案,以防有人评论或更正。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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