简体   繁体   English

在编译之前,如何使用MSBuild重命名源文件?

[英]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. 您应该能够同时使用SourceFilesDestinationFiles将文件重命名为副本的一部分。

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

相关问题 你如何将条件编译符号(DefineConstants)传递给msbuild - How do you pass conditional compilation symbols (DefineConstants) to msbuild Visual Studio MSbuild重命名文件事件 - Visual Studio MSbuild rename file event 在 msbuild 将二进制文件打包到单个文件之前如何访问二进制文件 - How to access binary before msbuild packs it to single file 如何通过C#以编程方式在MSBuild中使用SLN文件? - How can I use an SLN file with MSBuild programmatically from C#? 如何访问在自定义错误页面中使用的异常的源错误,源文件和行号? - How do you access the Source Error, Source File and Line Number of an exception to use in a custom error page? 如何使用名为Configuration的MSBuild命令行参数作为条件编译符号? - How to use the MSBuild command line parameter called Configuration as a conditional compilation symbol? 重命名WCF服务源文件 - Rename WCF service source file 如何使用tfs构建定义来运行自定义msbuild文件? - How to use tfs build definition to run custom msbuild file? 如何使用SSIS有条件地使用唯一名称重命名目录中的每个文件? - How can I use SSIS to conditionally rename each file in a directory with a unique name? 如何在Oracle存储过程中重命名变量? - How can you rename variables in an Oracle stored procedure?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM