[英]How can you use MSBuild to rename a source file before compilation?
I have a problem where I want to rename/move/copy a source XAML file before compiling it. 我在编译源XAML文件之前要重命名/移动/复制该文件时遇到问题。 I can see that there is a Move and a Copy task as a part of MSBuild that you can put into the .csproj file and it will do this. 我可以看到,有一个Move和Copy任务是MSBuild的一部分,您可以将其放入.csproj文件中。 Unfortunately, I have only been able to get this to work with compiled files. 不幸的是,我只能使它与编译文件一起使用。 Are either of these tasks supposed to work on the source files themselves? 这些任务中的任何一个都应该在源文件上运行吗?
If it is of any value, I'll elaborate a bit on what I'm trying to do, in case somebody has a completely different solution. 如果它有任何价值,我会详细说明我想做的事情,以防有人使用完全不同的解决方案。 Basically, our WPF application needs to be brandable. 基本上,我们的WPF应用程序需要具有品牌效应。 We've got the different brands in different XAML files (different icons and properties, etc.). 我们在不同的XAML文件中拥有不同的品牌(不同的图标和属性等)。 These files are named something along the lines of BrandA.xaml, BrandB.xaml, etc. I'm currently trying to get exactly one of those brand files to be compiled into just simply Brand.xaml, which the rest of the application would then load. 这些文件的名称类似于BrandA.xaml,BrandB.xaml等。我目前正试图将这些品牌文件之一准确地编译为简单的Brand.xaml,然后其余的应用程序将对其进行编译。加载。 I've been able to get just a single file to copy over using MSBuild using conditions, but I haven't been able to get it named correctly. 使用条件,我只能使用MSBuild复制单个文件,但无法正确命名。
Don't include the different brands as Page
, but rather your custom item type, eg Brand
(to ensure it's still part of the project and shows up in Visual Studio): 不要包括不同的品牌作为Page
,而是包括您的自定义项目类型,例如Brand
(以确保它仍然是项目的一部分并显示在Visual Studio中):
<Brand Include="BrandA.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Brand>
You can then use the BeforeBuild
target to copy the relevant file to Brand.xaml
and include it in the Page
item group. 然后,您可以使用BeforeBuild
目标将相关文件复制到Brand.xaml
并将其包括在Page
项目组中。 You should be able to use both SourceFiles
and DestinationFiles
to rename the file as part of the copy. 您应该能够同时使用SourceFiles
和DestinationFiles
将文件重命名为副本的一部分。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.