2

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

2
  • If you are trying to deploy, then why do you need to modify the csproj file? Commented Jan 21, 2012 at 19:25
  • @JohnSaunders thanks, I've just added some more info to the Q. Does this clarify it? Commented Jan 21, 2012 at 20:07

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

6 Comments

Thanks Oded, do you know if MSBuild or any Visual Studio command line util can modify references? If not I'm sure I could code one up quite quickly. Regards,
@Dr.AndrewBurnett-Thompson - Not that I am aware of. This is something very much out of the ordinary (as project/solution files do not normally need to be changed as part of compilation).
fair enough, appreciate the answer! Csproj hacking it is :)
@Dr.AndrewBurnett-Thompson - XDocument is your friend ;)
vbscript might be useful here (to avoid yet another csproj, sln just to change one line of XML file)
|
2

I don't understand why you would need to modify the csproj file in your case. Just make sure the library reference in the csproj file is relative, i.e. ..\..\..\SDK\WPF\4.0\ControlLibrary.dll and it will keep working fine even if you move the complete folder hierarchy to a new location.

If you're trying to simplify adding the library to new projects though, take a look at NuGet. It's the best way for distributing and deploying libraries.

3 Comments

thanks for your answer Damir. Its not possible to use a relative reference in this case. I've updated the Q to clarify the requirement
Nuget looks interesting. Do you know if this can be used for commercial dlls too? This one will have a tined trial + developer license key to unlock when purchased. If license keys were distributed via a separate site could locked all be distributed via nuget?
@Dr.AndrewBurnett-Thompson I'm not sure about the NuGet Online Gallery terms and conditions for publishing packages but I suppose it is allowed. There are at least a couple of commercial libraries published already: RavenDB, JustMock and Kendo UI among them.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.