none
Compile C# without installing .net framework RRS feed

  • Question

  • Our C# code needs to be compiled with .net 3.5, but our building machines (tens of them) may not have 3.5 installed. We are not allowed to install any software on those machines. So the question is how do I build the C# code on those Windows machine? Is it possible to copy the necessary libraries and use csc.exe or msbuild to build the C#. I copied the whole framework folder onto a Windows machine that doesn't have 3.5 installed. I tried to run csc.exe or msbuild.exe. Neither worked. I guess the registry entries are the main issues. Anybody here know how to this? If it is possible, what is the minimum set of files I need to copy?

    I am talking about code compilation. Whoever uses the generated dll files will have .net 3.5 installed on his/her machine.  

    • Edited by Markch1 Tuesday, April 3, 2012 12:10 AM
    Tuesday, April 3, 2012 12:03 AM

Answers

  • No I think you have the proper tool.  So with this you now have a list of minimum things needed to invoke CSC known by it's PE header.  These are the objects it uses to do it's stuff.  Your build systems would have to have these things at a minimum.

    Next you have to know a bit of the internals of CSC like what other things it does.  Registry settings and other gotchas which won't be that easy to find.  This is the hard part of this.  What else do you need?  Start first by getting a system that only has csc.exe and the files above, then test the compile.  Hopefully the program will tell you what it doesn't like, but even if it doesn't tell you outright you can deduce it by downloading and running WINDBG.exe to find out.


    JP Cowboy Coders Unite!

    Tuesday, April 3, 2012 6:13 PM
  • When an executable is loaded over on the unmanged side the first thing it does it attempt to load all the dependencies.  Then as the program's entry point starts to run, that's when the configuration stuff comes into play.  Windbg shows the entire shooting match.  Good luck, but wouldn't it be nice to tell your build team to get with it?

    JP Cowboy Coders Unite!

    Tuesday, April 3, 2012 6:15 PM

All replies

  • I think it depends on the portions of .Net 3.5 you are using, and whether you have at least .Net 2.0 on the machines.  For example, I know that I was able to run an application which referenced the .Net charting dll (DataVisualization?) by targeting 2.0 and using "copy local" for the charting dll.
     
    Why do you think you need to build your app on the target machines rather than copying the built application?  You may not even need to "install" your app.
     
    --
    Mike
    Tuesday, April 3, 2012 12:24 AM
  • Compiling a program is the first step and I think it is possible to compile a program without .NET being installed (because you can specify manually for csc.exe the assemblies a program requires). But after that you naturally want to run the program. How will you do that without a .NET Framework being installed?
    Tuesday, April 3, 2012 4:33 AM
  • Our C# code needs to be compiled with .net 3.5, but our building machines (tens of them) may not have 3.5 installed. We are not allowed to install any software on those machines. So the question is how do I build the C# code on those Windows machine? Is it possible to copy the necessary libraries and use csc.exe or msbuild to build the C#. I copied the whole framework folder onto a Windows machine that doesn't have 3.5 installed. I tried to run csc.exe or msbuild.exe. Neither worked. I guess the registry entries are the main issues. Anybody here know how to this? If it is possible, what is the minimum set of files I need to copy?

    I am talking about code compilation. Whoever uses the generated dll files will have .net 3.5 installed on his/her machine.  

    Then you should not be using .NET at all or you should write a compiler for yourself. If, you are not supposed install anything(!) on client machine, then write the code in C++ using Win32 SDK. On the other hand, if you have already written the code, then there is no way but to install framework on client machine.


    Please mark this post as answer if it solved your problem. Happy Programming!

    Tuesday, April 3, 2012 4:48 AM
  • Adavesh, building != running.  The compiler for C# isn't written in .NET, so it's at least conceivable that it doesn't require .NET to run.  Obviously it would be able to run the compiled program, but if it's an automated build server it likely doesn't need to.
    Tuesday, April 3, 2012 2:59 PM
  • As servy says: building != running... That's a very important point.  First of all most shops have just one build machine and build there.  If you use installsheild you create installs from the builds on that one machine.  But even if you don't you have many other options to deploy. Secondly if you have an approved project for .net 3.5 and your build team won't upgrade, that's a Managerial problem.

    But having said all of that if you still need to do this, I recommend that you find the dependency walker software (I think it's in Windows SDK) and allow that tool to tell you all the dependencies needed for csc.exe.  However, you still have issues as you described with configurations and registry settings.  It's probably do-able but may not be easy.


    JP Cowboy Coders Unite!

    Tuesday, April 3, 2012 3:33 PM
  • Mansoor asks the perfect question:  How can you run .NET 3.5 compiled code on a system without .NET 3.5?

    JP Cowboy Coders Unite!

    Tuesday, April 3, 2012 3:34 PM
  • Thanks for everybody's reply.

    My only issue is how to build the code on the daily build machine without installing .net 3.5. The client whoever uses the generated dlls will have .net frameworkd 3.5 installed.

    Anybody knows what subset of .net 3.5 is needed to achieve this goal?

    Tuesday, April 3, 2012 4:10 PM
  • I'd consider copying all these files in the correct folder onto the build machines the same as "Installing" especially if you start to consider setting the registry values as well. It's better to just install the Windows SDK for .NET 3.5 onto the build machine, that way you at least know that the machines will be dependable. If you're copy/pasting binaries onto the machine, there's no way of knowing everything is building as intended.

    Though the C# compiler itself is written in C++ and might not depend on the .NET framework to be present to at least execute, msbuild does. So do many of the other tools which are used during the build process (resource file generation, assembly linking, webservice proxy generation, fxcop among others). Whether they need .NET 3.5 or 2.0 varies.

    Then there's the issue that the .NET 3.5 installation includes a few hotfixes for .NET 2.0 and these might be rather important if your code depends on these.

    All in all: The recommendation is to install the .NET 3.5 Platform SDK + SP + latest Roll-up on your build servers. Or at least some of the, If you're using Team Build, you can use build agent tagging to direct builds to specific build servers. If you're using another product for building your solution you might be able to use a similar technique.


    My blog: blog.jessehouwing.nl

    Tuesday, April 3, 2012 4:11 PM
  • Guys, I would not have asked the question if I could install .net framework 3.5 on the building machines.

    We have tens of building machines that compile different kinds of code, hundreds times a day. Those machines are in a building pool and I even don't know which machine will do my compilation job. I am trying to find a way to build this C# project (very small compared to other projects) using a C# compiler that doesn't need .net V3.5 installation. Thanks,

    Tuesday, April 3, 2012 4:21 PM
  • Start by getting dependency walker.  You are going to have to decompile/find all the dependencies for CSC.EXE including Registry entries.


    JP Cowboy Coders Unite!

    Tuesday, April 3, 2012 5:29 PM
  • I got a dependency walker. it show all the dependencies in the C:\Windows\System32 and its sub folders.

    Mr. Javaman II, do you have any specific Dependency walker that can show more details?


    This is the one I used. dependencywalker.comscreen shot
    • Edited by Markch1 Tuesday, April 3, 2012 5:59 PM
    Tuesday, April 3, 2012 5:53 PM
  • No I think you have the proper tool.  So with this you now have a list of minimum things needed to invoke CSC known by it's PE header.  These are the objects it uses to do it's stuff.  Your build systems would have to have these things at a minimum.

    Next you have to know a bit of the internals of CSC like what other things it does.  Registry settings and other gotchas which won't be that easy to find.  This is the hard part of this.  What else do you need?  Start first by getting a system that only has csc.exe and the files above, then test the compile.  Hopefully the program will tell you what it doesn't like, but even if it doesn't tell you outright you can deduce it by downloading and running WINDBG.exe to find out.


    JP Cowboy Coders Unite!

    Tuesday, April 3, 2012 6:13 PM
  • When an executable is loaded over on the unmanged side the first thing it does it attempt to load all the dependencies.  Then as the program's entry point starts to run, that's when the configuration stuff comes into play.  Windbg shows the entire shooting match.  Good luck, but wouldn't it be nice to tell your build team to get with it?

    JP Cowboy Coders Unite!

    Tuesday, April 3, 2012 6:15 PM