简体   繁体   English

MSBuild和CSPROJ:如何调整C#文件的包含/编译

[英]MSBuild and csproj: how to conditioning c# file inclusion/compiling

I have a Xamarin Android+iOS application with a .NET standard library, and I want to condition the compiling of some .cs files in my library depending on the package in the AndroidManifest.xml / the bundle identifier in the info.plist. 我有一个.NET标准库Xamarin的Android + iOS的应用程序,我想这取决于封装在AndroidManifest.xml /中的info.plist 束标识符来调理的一些文件的.cs编译在我的图书馆。 This because I need to customize the app for more customers with different configurations. 这是因为我需要为具有不同配置的更多客户定制应用程序。 The condition should also consider if my configuration is Debug or Release (file need to be excluded only in Release configuration). 条件还应考虑我的配置是“调试”还是“发行”(仅在“ 发行”配置中需要排除文件)。

<Compile Include="ConditionalFile.cs" Condition="'$(Configuration)' == 'Debug'" />

The condition for the debug, I need to add some kind of "or clause" and to fill it, maybe with a bash script launched when it's time to compile the apk/ipa. 调试的条件是,我需要添加某种“或子句”并填充它,也许需要在编译apk / ipa时启动bash脚本。

Any idea? 任何想法?

One solution I've found is this one: 我发现的一种解决方案是:

  • Custom property with the id of my app: <PackageId>it.mpic.x</PackageId> 具有我的应用程序ID的自定义属性: <PackageId>it.mpic.x</PackageId>

  • bash script which changes the <PackageId> element with the right app-id before the release bash脚本,该脚本在发布之前使用正确的app-id更改<PackageId>元素

  • Compile condition in or: Condition="'$(Configuration)' == 'Debug' Or '$(PackageId)' == 'it.mpic.x1'" 在以下Condition="'$(Configuration)' == 'Debug' Or '$(PackageId)' == 'it.mpic.x1'"编译条件: Condition="'$(Configuration)' == 'Debug' Or '$(PackageId)' == 'it.mpic.x1'"

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

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