1

I am writing a webservice, that when called should build a C# project. I'm using the framework 2 reference, Microsoft.Buld.Engine and Microsoft.Build.Framework. If you look under the '<Import>' section .csproj file, by default it has:

<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

which I then changed to:

<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />

My code to build the csproj is:

Engine buildEngine = new Engine(Path.Combine(Environment.GetEnvironmentVariable("SystemRoot"), @"Microsoft.NET\Framework\v2.0.50727"));
FileLogger logger = new FileLogger();
logger.Parameters = @"logfile=c:\temp\build.log";
buildEngine.RegisterLogger(logger);

bool success = buildEngine.BuildProjectFile([Path_Of_Directory]+ "ProjectName.csproj");
buildEngine.UnregisterAllLoggers();

The success variable returns a false because the build faild. I then check the build.log file and this is the error I recieve:

Build started 3/17/2010 11:16:56 AM Project "[Path_Of_Directory]\ProjectName.csproj" (default targets): Target GetFrameworkPaths: Could not locate the .NET Framework SDK. The task is looking for the path to the .NET Framework SDK at the location specified in the SDKInstallRootv2.0 value of the registry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft.NETFramework. You may be able to solve the problem by doing one of the following: 1.) Install the .NET Framework SDK. 2.) Manually set the above registry key to the correct location. Target

I cant understand why it wont build. Any help will be much appreciated. Thanks

abatishchev
  • 98,240
  • 88
  • 296
  • 433
Yo Momma
  • 8,581
  • 7
  • 34
  • 45
  • What exactly do you not understand? The error message tells you exactly what to check first. Did you do that? – TomTom Mar 17 '10 at 09:23
  • Yes, The registry value is "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727", which is exactly the same as the bin path I am passing through, hence my dilema – Yo Momma Mar 17 '10 at 09:30

4 Answers4

4

Use /ToolsVersion:3.5

As per http://blogs.msdn.com/b/msbuild/archive/2006/11/15/multi-targeting-how-does-it-work.aspx

ToolsVersion is the parameter that you use to force a project to build using a specific toolset.

JasonPlutext
  • 15,352
  • 4
  • 44
  • 84
1

You can try to verify the SDK path by building this project:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <Target Name="GetPath">
        <GetFrameworkSdkPath>
            <Output
                TaskParameter="Path"
                PropertyName="SdkPath" />
        </GetFrameworkSdkPath>
        <Message Text="$(SdkPath)"/>
    </Target>
</Project>

I may be wrong, but the path C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727 you are seeing does not seem correct.

It should rather be C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\ or C:\Program Files\Microsoft SDKs\Windows\v6.0A.

Filburt
  • 17,626
  • 12
  • 64
  • 115
  • Filbert, you brought me closer to my answer. It was the right binpath folder, but the .csprof file was referencing another project instead of it's .dll and was searching for the project in the binpath folder, hence the errors. I removed the reference to the project and added a reference to the dll in the bin folder of the project being referenced and magic, it works. – Yo Momma Mar 17 '10 at 11:37
1

On further investigation, I found the true reason for the error. To recap on the application I'm creating:

It's a webservice created in framework 3.5 trying to build a C# project developed using framework 2.

When one adds the two refrences, Microsoft.Buld.Engine and Microsoft.Build.Framework, you will notice that there are two versions of each.One version being a framework 2 version and one being a framwork 3.5 version. Since the project I was trying to build is done in framework 2, I imported the framework 2 version. This is where the error lies.

The Solution: The BinPath should be the only reference to framework two ie: "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727". Microsoft.Buld.Engine and Microsoft.Build.Framework should point to the 3.5 version since the application doing the building is developed in framework 3.5. I suppose if it was developed in framework 2, I would of never had an issue in the first place.

Yo Momma
  • 8,581
  • 7
  • 34
  • 45
1

you can try like this way :

Find the Assemply from C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\Microsoft.Build.Engine.dll. Copy and Past into GAC Location as below mentioned:

C:\Windows\assembly\GAC_MSIL\Microsoft.Build.Engine\3.5.0.0__b03f5f7f11d50a3a

it's working. problem because of GAC file is missing.

baskaran
  • 11
  • 1