可以通过批处理文件以编程方式删除并添加对csproj的引用? [英] Possible to remove and add a reference to csproj programmatically via a batch file?

查看:185
本文介绍了可以通过批处理文件以编程方式删除并添加对csproj的引用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个短批处理文件来准备一个控制库DLL,其中包含通过sip文件进行部署的示例项目,并具有以下问题。给定已知位置的csproj文件和已知位置的DLL,可以通过编程方式从批处理文件更新csproj(通过第三方命令行exe,或其他脚本)添加新的DLL?



我的文件夹结构是

  / Build 
/ SDK
/ WPF
/4.0:ControlLibrary.dll坐在这里
/示例
/ WPF
/4.0:Examples.csproj坐在这里

假设批处理文件位于/ Build级别,有没有办法修改Examples.csproj来引用ControlLibrary.dll? p>

只是为了澄清,我有这样的结构的原因是我希望部署一个示例csproj与我的控制库一起发货。 examples.csproj应该引用SDK /下的混淆控制库。 examples.csproj也存在于dev trunk(已从其中复制)中,而在开发解决方案中,它以非混淆形式引用ControlLibrary.csproj的输出。



im创建这里是一个文件夹结构来压缩和运送ControlLibrary加上示例,因此需要更新引用。



更新 - 使用Powershell解决



请参阅添加和删除参考资料中的相关问题和答案使用Powershell

解决方案

csproj 文件是XML文件 - 您可以轻松地编写一个命令行应用程序来处理这些文件(添加,删除节点等)。



您可以从批处理文件中调用这样一个命令行应用程序。 p>

您可以在以下位置找到此文件的架构:

 %windir% \Microsoft.NET\Framework\ [框架版本] \Microsoft.Build.xsd 

这样的答案


I am writing a short batch file to prepare a control library DLL with Examples project for deployment via sip file and have the following question.

Given a csproj file at known location and a DLL at known location, is it possible to programmatically update the csproj from the batch file (via third party command line exe, or other scripting) to add the new DLL?

My folder structure is

/Build 
   /SDK
      /WPF
          /4.0 : ControlLibrary.dll sits here
   /Examples
      /WPF
          /4.0 : Examples.csproj sits here

Assuming the batch file is at the /Build level, is there any way to modify Examples.csproj to reference ControlLibrary.dll ?

Just to clarify, the reason why I have the structure like this is I wish to deploy an examples csproj to ship with my control library. Examples.csproj should reference the obfuscated control library under SDK/. Examples.csproj also exists on dev trunk (where it has been copied from) and in the development solution it references output of ControlLibrary.csproj on non obfuscated form.

Essentially what im creating here is a folder structure to zip up and ship the ControlLibrary plus examples, hence, the need to update the reference.

Update - Solved using Powershell

Please see this related question and answer on adding and removing references using Powershell

解决方案

csproj files are XML files - you can easily write a command line application to manipulate these files (adding, removing nodes etc).

You can call such a command line application from your batch file.

You can find the schema for this file at:

%windir%\Microsoft.NET\Framework\[framework version]\Microsoft.Build.xsd

As described in this SO answer.

这篇关于可以通过批处理文件以编程方式删除并添加对csproj的引用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆