How to plug your own C# compiler into VS 2005.
Jomo Fisher--A bunch of future C# compiler features (think 3.0 and beyond) will be on display at PDC in a couple of weeks. We wanted to ship a nice installation that lets people try out the new features of the compiler while still leaving VS 2005 working for regular 2005 C# projects. MSBuild made this insanely easy.
I wasn't going to post the technical details because, really, how many people need to plug in a replacement for the C# compiler? Well, this guy does: https://channel9.msdn.com/ShowPost.aspx?PostID=107239#107239. So I think I'll talk about it a little bit in case other people are interested.
Here are the steps to replace the C# compiler for a single project. This assumes the your compiler is called CSC.EXE and is switch-compatible with CSC.EXE from VS 2005.
(1) Create a plain old C# project.
(2) Edit the .CSPROJ file with notepad and replace the <Import ...> line with
<Import Project="c:\MySubfolder\MyTargets.targets" />
(3) Create "c:\MySubfolder\MyTargets.targets" and put this in there:
<Project
DefaultTargets="Build"
xmlns="https://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<CscToolPath>c:\MySubfolder\</CscToolPath>
<UseHostCompilerIfAvailable>false</UseHostCompilerIfAvailable>
</PropertyGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>
(4) Save everything.
(5) Put your replacement CSC.EXE in c:\MySubfolder
That's it. You can load up your project and build with your own compiler. One big caveat is that you'll still get the regular C# 2.0 IntelliSense(tm) when editing in VS.
Make it into a Project Template
Once you have the project building. You can make it into a project template by going to File\Export Template... in VS 2005.
This posting is provided "AS IS" with no warranties, and confers no rights.
Comments
- Anonymous
August 31, 2005
The comment has been removed - Anonymous
August 31, 2005
I understand this is the technique for changing the location of the C# compiler used to build the project. Where can we find a description of the technique for plugging in a new language entirely (with custom IntelliSense, custom compiler, potentially custom build steps, etc)? - Anonymous
August 31, 2005
The comment has been removed - Anonymous
September 02, 2005
I remember looking at this a month ago, and I remember wishing there was some good end-to-end how-to on the matter.