function code_msvc_vcproj_file(fileNameInfo)

%   Copyright 1995-2013 The MathWorks, Inc.

    global gMachineInfo gTargetInfo

    fileName = fileNameInfo.msvcvcprojFile;
    sf_echo_generating('Coder',fileName);
    file = fopen(fileName,'Wt');
    if file<3
        construct_coder_error([],sprintf('Failed to create file: %s.',fileName),1);
    end

    DOLLAR = '$';
    
    isWin32 = strcmp(computer,'PCWIN32');
    machineName = gMachineInfo.machineName;
    
    srcDirectory = fileNameInfo.targetDirRelPath;

fprintf(file,'<?xml version="1.0" encoding="shift_jis"?>\n');
fprintf(file,'<VisualStudioProject\n');
fprintf(file,'	ProjectType="Visual C++"\n');
fprintf(file,'	Version="9.00"\n');
fprintf(file,'	Name="%s_sfun"\n',machineName);
fprintf(file,'	ProjectGUID="{550BDE80-36D1-48AE-AF02-733636C11CED}"\n');
fprintf(file,'	TargetFrameworkVersion="0"\n');
fprintf(file,'	>\n');
fprintf(file,'	<Platforms>\n');
fprintf(file,'		<Platform\n');
fprintf(file,'			Name="x64"\n');
fprintf(file,'		/>\n');
fprintf(file,'	</Platforms>\n');
fprintf(file,'	<Configurations>\n');
fprintf(file,'		<Configuration\n');
fprintf(file,'			Name="Debug|x64"\n');
fprintf(file,'			OutputDirectory="%s(PlatformName)\\%s(ConfigurationName)"\n',DOLLAR,DOLLAR);
fprintf(file,'			IntermediateDirectory="%s(PlatformName)\\%s(ConfigurationName)"\n',DOLLAR,DOLLAR);
fprintf(file,'			ConfigurationType="2"\n');
fprintf(file,'			UseOfMFC="0"\n');
fprintf(file,'			ATLMinimizesCRunTimeLibraryUsage="false"\n');
fprintf(file,'			>\n');
fprintf(file,'			<Tool\n');
fprintf(file,'				Name="VCMIDLTool"\n');
fprintf(file,'				PreprocessorDefinitions="_DEBUG"\n');
fprintf(file,'				MkTypLibCompatible="true"\n');
fprintf(file,'				SuppressStartupBanner="true"\n');
fprintf(file,'				TargetEnvironment="3"\n');
fprintf(file,'				TypeLibraryName=".\\./%s_sfun.tlb"\n',machineName);
fprintf(file,'				HeaderFileName=""\n');
fprintf(file,'			/>\n');

    allIncludeDirs = [fileNameInfo.userIncludeDirs,...
                      {srcDirectory},...
                      {fileNameInfo.sfRuntimeIncludeDir},... % XXX (aelseed)
                      {[fileNameInfo.matlabRoot,'\extern\include']},...
                      {[fileNameInfo.matlabRoot,'\simulink\include']}];
        
    incDirString = allIncludeDirs{1};
    for i = 2:length(allIncludeDirs)
        incDirString    = [incDirString,',',allIncludeDirs{i}]; %#ok<AGROW>
    end

fprintf(file,'			<Tool\n');
fprintf(file,'				Name="VCCLCompilerTool"\n');
fprintf(file,'				Optimization="0"\n');
fprintf(file,'				AdditionalIncludeDirectories="%s"\n',incDirString);
fprintf(file,'				PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;MATLAB_MEX_FILE"\n');
fprintf(file,'				MinimalRebuild="true"\n');
fprintf(file,'				RuntimeLibrary="2"\n');
fprintf(file,'				StructMemberAlignment="8"\n');
fprintf(file,'				PrecompiledHeaderFile=".\\Debug/%s_sfun.pch"\n',machineName);
fprintf(file,'				AssemblerListingLocation=".\\Debug/"\n');
fprintf(file,'				ObjectFile=".\\Debug/"\n');
fprintf(file,'				ProgramDataBaseFileName=".\\Debug/"\n');
fprintf(file,'				WarningLevel="3"\n');
fprintf(file,'				SuppressStartupBanner="true"\n');
fprintf(file,'				DebugInformationFormat="3"\n');
fprintf(file,'				CallingConvention="1"\n');
fprintf(file,'			/>\n');

    if(isWin32)
        libMexDir = fullfile(matlabroot,'extern','lib','win32','microsoft');
    else
        libMexDir = fullfile(matlabroot,'extern','lib','win64','microsoft');
    end
    
    allLibs = {fullfile(libMexDir,'libmx.lib'),...
                  fullfile(libMexDir,'libmex.lib'),...
                  fullfile(libMexDir,'libmat.lib'),...
                  fullfile(libMexDir,'libfixedpoint.lib'),...
                  fullfile(libMexDir,'libut.lib'),...
                  fullfile(libMexDir,'libmwmathutil.lib'),...
                  fullfile(libMexDir,'libemlrt.lib'),...
                  fullfile(libMexDir,'sf_runtime.lib'),...
                  fullfile(libMexDir,'libcovrt.lib')};
                  
    numLinkMachines = length(fileNameInfo.linkLibFullPaths);
    if(numLinkMachines)
        for i = 1:numLinkMachines
            allLibs{end+1} = fileNameInfo.linkLibFullPaths{i}; %#ok<AGROW>
        end
    end
    for i = 1:length(fileNameInfo.userLibraries)
        allLibs{end+1} = fileNameInfo.userLibraries{i}; %#ok<AGROW>
    end
    libString = '';
    for i=1:length(allLibs)
       libString = [libString,'&quot;', allLibs{i},'&quot; ']; %#ok<AGROW>
    end

fprintf(file,'			<Tool\n');
fprintf(file,'				Name="VCLinkerTool"\n');
fprintf(file,'				AdditionalOptions="/export:mexFunction"\n');
fprintf(file,'				AdditionalDependencies="%s"\n',libString);
fprintf(file,'				OutputFile="%s_sfun.%s"\n',machineName,mexext);
fprintf(file,'				LinkIncremental="2"\n');
fprintf(file,'				SuppressStartupBanner="true"\n');
fprintf(file,'				GenerateDebugInformation="true"\n');
fprintf(file,'				ProgramDatabaseFile=".\\./%s_sfun.pdb"\n',machineName);
fprintf(file,'				SubSystem="2"\n');
fprintf(file,'				RandomizedBaseAddress="1"\n');
fprintf(file,'				DataExecutionPrevention="0"\n');
fprintf(file,'				ImportLibrary=".\\./%s_sfun.lib"\n',machineName);
fprintf(file,'				TargetMachine="17"\n');
fprintf(file,'			/>\n');
fprintf(file,'			<Tool\n');
fprintf(file,'				Name="VCBscMakeTool"\n');
fprintf(file,'				SuppressStartupBanner="true"\n');
fprintf(file,'				OutputFile=".\\./%s_sfun.bsc"\n',machineName);
fprintf(file,'			/>\n');
fprintf(file,'		</Configuration>\n');
fprintf(file,'	</Configurations>\n');
fprintf(file,'	<Files>\n');

    for i=1:length(fileNameInfo.userSources)
fprintf(file,'		<File\n');
fprintf(file,'			RelativePath="%s"\n',fileNameInfo.userSources{i});
fprintf(file,'			>\n');
fprintf(file,'		</File>\n');
    end
    for chart=gMachineInfo.charts
        chartNumber = sf('get',chart,'chart.number');
        for i = 1:length(fileNameInfo.chartSourceFiles{chartNumber+1})
fprintf(file,'		<File\n');
fprintf(file,'			RelativePath="%s\\%s"\n',srcDirectory,fileNameInfo.chartSourceFiles{chartNumber+1}{i});
fprintf(file,'			>\n');
fprintf(file,'		</File>\n');
        end
    end

fprintf(file,'		<File\n');
fprintf(file,'			RelativePath="%s\\%s"\n',srcDirectory,fileNameInfo.machineSourceFile);
fprintf(file,'			>\n');
fprintf(file,'		</File>\n');

    if(~gTargetInfo.codingLibrary)
fprintf(file,'		<File\n');
fprintf(file,'			RelativePath="%s\\%s"\n',srcDirectory,fileNameInfo.machineRegistryFile);
fprintf(file,'			>\n');
fprintf(file,'		</File>\n');
    end
    
fprintf(file,'	</Files>\n');
fprintf(file,'</VisualStudioProject>\n');
              

    fclose(file);
