Handle defines and unsafe code.

This commit is contained in:
David Fowler 2014-01-25 05:31:46 -08:00
parent 97c064af5c
commit 84f35cab5e
3 changed files with 23 additions and 10 deletions

View File

@ -150,6 +150,7 @@ functions
var d = serializer.DeserializeObject(jsonText) as IDictionary<string, object>; var d = serializer.DeserializeObject(jsonText) as IDictionary<string, object>;
var configs = GetObject(d, "configurations") ?? new Dictionary<string, object>(); var configs = GetObject(d, "configurations") ?? new Dictionary<string, object>();
var dependencies = GetObject(d, "dependencies") ?? new Dictionary<string, object>(); var dependencies = GetObject(d, "dependencies") ?? new Dictionary<string, object>();
var compilationOptions = GetObject(d, "compilationOptions") ?? new Dictionary<string, object>();
if(configs.Count == 0) if(configs.Count == 0)
{ {
@ -173,6 +174,11 @@ functions
.Select(r => r.Key) .Select(r => r.Key)
.ToList(); .ToList();
var defines = Get<IEnumerable<object>>(compilationOptions, "define") ?? new object[0];
object unsafeValue = Get<object>(compilationOptions, "allowUnsafe");
bool allowUnsafeCode = unsafeValue == null ? false : (bool)unsafeValue;
string extraProperties = allowUnsafeCode ? "\n<AllowUnsafeBlocks>true</AllowUnsafeBlocks>" : "";
// HACK: Assume the packages folder is 2 up from the projectDir // HACK: Assume the packages folder is 2 up from the projectDir
string packagesDir = Path.GetFullPath(Path.Combine(projectDir, "..", "..", "packages")); string packagesDir = Path.GetFullPath(Path.Combine(projectDir, "..", "..", "packages"));
@ -205,6 +211,8 @@ functions
var template = templates[targetFramework] var template = templates[targetFramework]
.Replace("{ProjectGuid}", id) .Replace("{ProjectGuid}", id)
.Replace("{Name}", projectName) .Replace("{Name}", projectName)
.Replace("{Defines}", String.Join(";", defines.Select(def => def.ToString())))
.Replace("{ExtraProperties}", extraProperties)
.Replace("{Files}", filesString) .Replace("{Files}", filesString)
.Replace("{ProjectReferences}", BuildProjectReferences(projectReferences, targetFramework, projectMapping)) .Replace("{ProjectReferences}", BuildProjectReferences(projectReferences, targetFramework, projectMapping))
.Replace("{References}", BuildReferences(packageReferences, gacReferences, packagesDir, targetFramework, GetCandidates(targetFramework))); .Replace("{References}", BuildReferences(packageReferences, gacReferences, packagesDir, targetFramework, GetCandidates(targetFramework)));
@ -340,15 +348,20 @@ functions
return sb.ToString(); return sb.ToString();
} }
private static IDictionary<string, object> GetObject(IDictionary<string, object> obj, string key) private static T Get<T>(IDictionary<string, object> obj, string key) where T : class
{ {
object value; object value;
if (obj.TryGetValue(key, out value)) if (obj.TryGetValue(key, out value))
{ {
return value as IDictionary<string, object>; return value as T;
} }
return null; return null;
} }
private static IDictionary<string, object> GetObject(IDictionary<string, object> obj, string key)
{
return Get<IDictionary<string, object>>(obj, key);
}
} }
} }

View File

@ -19,18 +19,18 @@
<DebugType>full</DebugType> <DebugType>full</DebugType>
<Optimize>false</Optimize> <Optimize>false</Optimize>
<OutputPath>bin\Debug\K</OutputPath> <OutputPath>bin\Debug\K</OutputPath>
<DefineConstants>DEBUG;TRACE;K10</DefineConstants> <DefineConstants>DEBUG;TRACE;K10;{Defines}</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>{ExtraProperties}
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget> <PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType> <DebugType>pdbonly</DebugType>
<Optimize>true</Optimize> <Optimize>true</Optimize>
<OutputPath>bin\Release\K</OutputPath> <OutputPath>bin\Release\K</OutputPath>
<DefineConstants>TRACE;K10</DefineConstants> <DefineConstants>TRACE;K10;{Defines}</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>{ExtraProperties}
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
{Files} {Files}

View File

@ -19,18 +19,18 @@
<DebugType>full</DebugType> <DebugType>full</DebugType>
<Optimize>false</Optimize> <Optimize>false</Optimize>
<OutputPath>bin\Debug\net45</OutputPath> <OutputPath>bin\Debug\net45</OutputPath>
<DefineConstants>DEBUG;TRACE;NET45</DefineConstants> <DefineConstants>DEBUG;TRACE;NET45;{Defines}</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>{ExtraProperties}
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget> <PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType> <DebugType>pdbonly</DebugType>
<Optimize>true</Optimize> <Optimize>true</Optimize>
<OutputPath>bin\Release\net45</OutputPath> <OutputPath>bin\Release\net45</OutputPath>
<DefineConstants>TRACE;NET45</DefineConstants> <DefineConstants>TRACE;NET45;{Defines}</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>{ExtraProperties}
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="mscorlib" /> <Reference Include="mscorlib" />