Prepare Flax.Build project for .NET 7
Add .NET SDK project generator and upgrade Flax.Build project files
This commit is contained in:
@@ -196,7 +196,7 @@ namespace Flax.Build
|
||||
var workspaceRoot = rootProject.ProjectFolderPath;
|
||||
var projectsRoot = Path.Combine(workspaceRoot, "Cache", "Projects");
|
||||
var projects = new List<Project>();
|
||||
var dotNetProjectGenerator = ProjectGenerator.Create(projectFormat, TargetType.DotNet);
|
||||
var dotNetProjectGenerator = ProjectGenerator.Create(projectFormat, TargetType.DotNetCore);
|
||||
var projectToBinaryModule = new Dictionary<Project, KeyValuePair<string, HashSet<Module>>>();
|
||||
var projectToModulesBuildOptions = new Dictionary<Project, Dictionary<Module, BuildOptions>>();
|
||||
Project mainSolutionProject = null;
|
||||
@@ -367,7 +367,7 @@ namespace Flax.Build
|
||||
|
||||
// Create project description
|
||||
var project = dotNetProjectGenerator.CreateProject();
|
||||
project.Type = TargetType.DotNet;
|
||||
project.Type = TargetType.DotNetCore;
|
||||
project.Name = project.BaseName = binaryModuleName;
|
||||
if (mainSolutionProject != null && projectInfo == rootProject)
|
||||
project.Name += ".CSharp"; // Prevent overlapping name with native code project
|
||||
@@ -480,7 +480,7 @@ namespace Flax.Build
|
||||
using (new ProfileEventScope("CreateProject"))
|
||||
{
|
||||
project = dotNetProjectGenerator.CreateProject();
|
||||
project.Type = TargetType.DotNet;
|
||||
project.Type = TargetType.DotNetCore;
|
||||
project.Name = project.BaseName = rulesProjectName;
|
||||
project.Targets = new[] { target };
|
||||
project.SearchPaths = new string[0];
|
||||
|
||||
@@ -334,6 +334,7 @@ namespace Flax.Build
|
||||
BuildTargetNativeCppBindingsOnly(rules, graph, target, buildContext, platform, architecture, configuration);
|
||||
break;
|
||||
case TargetType.DotNet:
|
||||
case TargetType.DotNetCore:
|
||||
BuildTargetDotNet(rules, graph, target, platform, configuration);
|
||||
break;
|
||||
default: throw new ArgumentOutOfRangeException();
|
||||
@@ -354,6 +355,7 @@ namespace Flax.Build
|
||||
BuildTargetNativeCpp(rules, graph, target, buildContext, toolchain, configuration);
|
||||
break;
|
||||
case TargetType.DotNet:
|
||||
case TargetType.DotNetCore:
|
||||
BuildTargetDotNet(rules, graph, target, toolchain.Platform, configuration);
|
||||
break;
|
||||
default: throw new ArgumentOutOfRangeException();
|
||||
|
||||
@@ -6,6 +6,7 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using Flax.Build.Graph;
|
||||
using Flax.Deploy;
|
||||
using Task = Flax.Build.Graph.Task;
|
||||
|
||||
namespace Flax.Build
|
||||
{
|
||||
|
||||
@@ -4,6 +4,7 @@ using System;
|
||||
using System.IO;
|
||||
using Flax.Build.Graph;
|
||||
using Flax.Build.NativeCpp;
|
||||
using Task = Flax.Build.Graph.Task;
|
||||
|
||||
namespace Flax.Build
|
||||
{
|
||||
|
||||
@@ -6,6 +6,7 @@ using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using Flax.Build.Graph;
|
||||
using Task = Flax.Build.Graph.Task;
|
||||
|
||||
namespace Flax.Build.BuildSystem.Graph
|
||||
{
|
||||
|
||||
@@ -19,9 +19,14 @@ namespace Flax.Build
|
||||
NativeCpp,
|
||||
|
||||
/// <summary>
|
||||
/// The C# project.
|
||||
/// The C# Mono project.
|
||||
/// </summary>
|
||||
DotNet,
|
||||
|
||||
/// <summary>
|
||||
/// The C# .NET SDK project.
|
||||
/// </summary>
|
||||
DotNetCore,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -19,7 +19,7 @@ public class FlaxBuildTarget : Target
|
||||
base.Init();
|
||||
|
||||
IsPreBuilt = false;
|
||||
Type = TargetType.DotNet;
|
||||
Type = TargetType.DotNetCore;
|
||||
OutputType = TargetOutputType.Library;
|
||||
Platforms = new[]
|
||||
{
|
||||
|
||||
@@ -161,6 +161,7 @@
|
||||
<Compile Include="Projects\VisualStudioCode\VisualStudioCodeInstance.cs" />
|
||||
<Compile Include="Projects\VisualStudioCode\VisualStudioCodeProjectGenerator.cs" />
|
||||
<Compile Include="Projects\VisualStudio\CSProjectGenerator.cs" />
|
||||
<Compile Include="Projects\VisualStudio\CSSDKProjectGenerator.cs" />
|
||||
<Compile Include="Projects\VisualStudio\IVisualStudioProjectCustomizer.cs" />
|
||||
<Compile Include="Projects\VisualStudio\VCProjectGenerator.cs" />
|
||||
<Compile Include="Projects\VisualStudio\VisualStudioInstance.cs" />
|
||||
|
||||
@@ -5,6 +5,7 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Flax.Build.Graph;
|
||||
using Flax.Build.NativeCpp;
|
||||
using Task = Flax.Build.Graph.Task;
|
||||
|
||||
namespace Flax.Build
|
||||
{
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Flax.Build.Graph;
|
||||
using Flax.Build.NativeCpp;
|
||||
using Task = Flax.Build.Graph.Task;
|
||||
|
||||
namespace Flax.Build.Platforms
|
||||
{
|
||||
|
||||
@@ -5,6 +5,7 @@ using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using Flax.Build.Graph;
|
||||
using Flax.Build.NativeCpp;
|
||||
using Task = Flax.Build.Graph.Task;
|
||||
|
||||
namespace Flax.Build
|
||||
{
|
||||
|
||||
@@ -54,7 +54,7 @@ namespace Flax.Build.Platforms
|
||||
StartInfo =
|
||||
{
|
||||
FileName = "/bin/sh",
|
||||
Arguments = string.Format("-c 'which {0}'", name),
|
||||
ArgumentList = { "-c", $"which {name}" },
|
||||
UseShellExecute = false,
|
||||
CreateNoWindow = true,
|
||||
RedirectStandardOutput = true,
|
||||
|
||||
@@ -7,6 +7,7 @@ using System.IO;
|
||||
using System.Text.RegularExpressions;
|
||||
using Flax.Build.Graph;
|
||||
using Flax.Build.NativeCpp;
|
||||
using Task = Flax.Build.Graph.Task;
|
||||
|
||||
namespace Flax.Build.Platforms
|
||||
{
|
||||
|
||||
@@ -9,6 +9,7 @@ using System.Xml;
|
||||
using Flax.Build.Graph;
|
||||
using Flax.Build.NativeCpp;
|
||||
using Flax.Build.Projects.VisualStudio;
|
||||
using Task = Flax.Build.Graph.Task;
|
||||
|
||||
// ReSharper disable InconsistentNaming
|
||||
|
||||
|
||||
@@ -8,6 +8,107 @@ using Newtonsoft.Json;
|
||||
|
||||
namespace Flax.Build
|
||||
{
|
||||
public class FlaxVersionConverter : JsonConverter
|
||||
{
|
||||
/// <summary>
|
||||
/// Writes the JSON representation of the object.
|
||||
/// </summary>
|
||||
/// <param name="writer">The <see cref="JsonWriter"/> to write to.</param>
|
||||
/// <param name="value">The value.</param>
|
||||
/// <param name="serializer">The calling serializer.</param>
|
||||
public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer)
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
writer.WriteNull();
|
||||
}
|
||||
else if (value is Version)
|
||||
{
|
||||
writer.WriteValue(value.ToString());
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new JsonSerializationException("Expected Version object value");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the JSON representation of the object.
|
||||
/// </summary>
|
||||
/// <param name="reader">The <see cref="JsonReader"/> to read from.</param>
|
||||
/// <param name="objectType">Type of the object.</param>
|
||||
/// <param name="existingValue">The existing property value of the JSON that is being converted.</param>
|
||||
/// <param name="serializer">The calling serializer.</param>
|
||||
/// <returns>The object value.</returns>
|
||||
public override object? ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer)
|
||||
{
|
||||
if (reader.TokenType == JsonToken.Null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (reader.TokenType == JsonToken.StartObject)
|
||||
{
|
||||
try
|
||||
{
|
||||
reader.Read();
|
||||
Dictionary<string, int> values = new Dictionary<string, int>();
|
||||
while (reader.TokenType == JsonToken.PropertyName)
|
||||
{
|
||||
var key = reader.Value as string;
|
||||
reader.Read();
|
||||
var val = (long)reader.Value;
|
||||
reader.Read();
|
||||
values.Add(key, (int)val);
|
||||
}
|
||||
|
||||
int major = 0, minor = 0, build = 0;
|
||||
values.TryGetValue("Major", out major);
|
||||
values.TryGetValue("Minor", out minor);
|
||||
values.TryGetValue("Build", out build);
|
||||
|
||||
Version v = new Version(major, minor, build);
|
||||
return v;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception(String.Format("Error parsing version string: {0}", reader.Value), ex);
|
||||
}
|
||||
}
|
||||
else if (reader.TokenType == JsonToken.String)
|
||||
{
|
||||
try
|
||||
{
|
||||
Version v = new Version((string)reader.Value!);
|
||||
return v;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception(String.Format("Error parsing version string: {0}", reader.Value), ex);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception(String.Format("Unexpected token or value when parsing version. Token: {0}, Value: {1}", reader.TokenType, reader.Value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether this instance can convert the specified object type.
|
||||
/// </summary>
|
||||
/// <param name="objectType">Type of the object.</param>
|
||||
/// <returns>
|
||||
/// <c>true</c> if this instance can convert the specified object type; otherwise, <c>false</c>.
|
||||
/// </returns>
|
||||
public override bool CanConvert(Type objectType)
|
||||
{
|
||||
return objectType == typeof(Version);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Contains information about Flax project.
|
||||
/// </summary>
|
||||
@@ -154,7 +255,7 @@ namespace Flax.Build
|
||||
/// </summary>
|
||||
public void Save()
|
||||
{
|
||||
var contents = JsonConvert.SerializeObject(this);
|
||||
var contents = JsonConvert.SerializeObject(this, new JsonSerializerSettings() { Converters = new[] { new FlaxVersionConverter() } });
|
||||
File.WriteAllText(ProjectPath, contents);
|
||||
}
|
||||
|
||||
@@ -180,7 +281,7 @@ namespace Flax.Build
|
||||
// Load
|
||||
Log.Verbose("Loading project file from \"" + path + "\"...");
|
||||
var contents = File.ReadAllText(path);
|
||||
var project = JsonConvert.DeserializeObject<ProjectInfo>(contents);
|
||||
var project = JsonConvert.DeserializeObject<ProjectInfo>(contents, new JsonSerializerSettings() { Converters = new[] { new FlaxVersionConverter() } });
|
||||
project.ProjectPath = path;
|
||||
project.ProjectFolderPath = Path.GetDirectoryName(path);
|
||||
|
||||
|
||||
@@ -135,6 +135,7 @@ namespace Flax.Build.Projects
|
||||
{
|
||||
case TargetType.NativeCpp: return new VCProjectGenerator(vsVersion);
|
||||
case TargetType.DotNet: return new CSProjectGenerator(vsVersion);
|
||||
case TargetType.DotNetCore: return new CSSDKProjectGenerator(vsVersion);
|
||||
default: throw new ArgumentOutOfRangeException(nameof(type), type, null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,257 @@
|
||||
// Copyright (c) 2012-2022 Wojciech Figat. All rights reserved.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Flax.Build.Projects.VisualStudio
|
||||
{
|
||||
/// <summary>
|
||||
/// The Visual Studio project generator for C# projects (.NET SDK .csproj).
|
||||
/// </summary>
|
||||
/// <seealso cref="Flax.Build.Projects.VisualStudio.VisualStudioProjectGenerator" />
|
||||
public class CSSDKProjectGenerator : VisualStudioProjectGenerator
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public CSSDKProjectGenerator(VisualStudioVersion version) : base(version)
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string ProjectFileExtension => "csproj";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override TargetType? Type => TargetType.DotNetCore;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void GenerateProject(Project project)
|
||||
{
|
||||
var csProjectFileContent = new StringBuilder();
|
||||
|
||||
var vsProject = (VisualStudioProject)project;
|
||||
var projectFileToolVersion = ProjectFileToolVersion;
|
||||
var projectDirectory = Path.GetDirectoryName(project.Path);
|
||||
var defaultTarget = project.Targets[0];
|
||||
foreach (var target in project.Targets)
|
||||
{
|
||||
// Pick the Editor-related target
|
||||
if (target.IsEditor)
|
||||
{
|
||||
defaultTarget = target;
|
||||
break;
|
||||
}
|
||||
}
|
||||
var defaultConfiguration = TargetConfiguration.Debug;
|
||||
var defaultArchitecture = TargetArchitecture.AnyCPU;
|
||||
var projectTypes = ProjectTypeGuids.ToOption(ProjectTypeGuids.WindowsCSharp);
|
||||
if (vsProject.CSharp.UseFlaxVS && VisualStudioInstance.HasFlaxVS)
|
||||
projectTypes = ProjectTypeGuids.ToOption(ProjectTypeGuids.FlaxVS) + ';' + projectTypes;
|
||||
|
||||
// Header
|
||||
csProjectFileContent.AppendLine("<Project Sdk=\"Microsoft.NET.Sdk\">");
|
||||
csProjectFileContent.AppendLine("");
|
||||
|
||||
//csProjectFileContent.AppendLine(string.Format("<Project DefaultTargets=\"Build\" ToolsVersion=\"{0}\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">", projectFileToolVersion));
|
||||
//csProjectFileContent.AppendLine(" <Import Project=\"$(MSBuildExtensionsPath)\\$(MSBuildToolsVersion)\\Microsoft.Common.props\" Condition=\"Exists('$(MSBuildExtensionsPath)\\$(MSBuildToolsVersion)\\Microsoft.Common.props')\" />");
|
||||
|
||||
// Properties
|
||||
|
||||
csProjectFileContent.AppendLine(" <PropertyGroup>");
|
||||
|
||||
switch (project.OutputType ?? defaultTarget.OutputType)
|
||||
{
|
||||
case TargetOutputType.Executable:
|
||||
csProjectFileContent.AppendLine(" <OutputType>Exe</OutputType>");
|
||||
break;
|
||||
case TargetOutputType.Library:
|
||||
csProjectFileContent.AppendLine(" <OutputType>Library</OutputType>");
|
||||
break;
|
||||
default: throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
|
||||
var baseConfiguration = project.Configurations.First();
|
||||
var baseOutputDir = Utilities.MakePathRelativeTo(project.CSharp.OutputPath ?? baseConfiguration.TargetBuildOptions.OutputFolder, projectDirectory);
|
||||
var baseIntermediateOutputPath = Utilities.MakePathRelativeTo(project.CSharp.IntermediateOutputPath ?? Path.Combine(baseConfiguration.TargetBuildOptions.IntermediateFolder, "CSharp"), projectDirectory);
|
||||
var baseConfigurations = project.Configurations.Select(x => x.Name.Split('|')[0]).Distinct().ToArray();
|
||||
|
||||
csProjectFileContent.AppendLine(" <TargetFramework>net7.0</TargetFramework>");
|
||||
csProjectFileContent.AppendLine(" <ImplicitUsings>enable</ImplicitUsings>");
|
||||
csProjectFileContent.AppendLine(" <Nullable>disable</Nullable>");
|
||||
csProjectFileContent.AppendLine(string.Format(" <Configurations>{0}</Configurations>", string.Join(";", baseConfigurations)));
|
||||
csProjectFileContent.AppendLine(" <EnableDefaultItems>false</EnableDefaultItems>"); // ?
|
||||
csProjectFileContent.AppendLine(" <GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>"); // Needed for Hostfxr
|
||||
csProjectFileContent.AppendLine(" <EnableDynamicLoading>true</EnableDynamicLoading>"); // ?
|
||||
csProjectFileContent.AppendLine(" <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>"); // Prevents outputting the file under net7.0 subdirectory
|
||||
csProjectFileContent.AppendLine(" <AssemblyName>$(MSBuildProjectName).CSharp</AssemblyName>"); // For backwards compatibility, keep the filename same
|
||||
csProjectFileContent.AppendLine(" <GenerateAssemblyInfo>false</GenerateAssemblyInfo>"); // Prevents AssemblyInfo.cs generation (causes duplicate attributes)
|
||||
csProjectFileContent.AppendLine(" <EnableBaseIntermediateOutputPathMismatchWarning>false</EnableBaseIntermediateOutputPathMismatchWarning>");
|
||||
csProjectFileContent.AppendLine(string.Format(" <OutDir>{0}</OutDir>", baseOutputDir)); // This needs to be set here to fix errors in VS
|
||||
csProjectFileContent.AppendLine(string.Format(" <IntermediateOutputPath>{0}</IntermediateOutputPath>", baseIntermediateOutputPath)); // This needs to be set here to fix errors in VS
|
||||
|
||||
csProjectFileContent.AppendLine(" </PropertyGroup>");
|
||||
csProjectFileContent.AppendLine("");
|
||||
|
||||
// Default configuration
|
||||
{
|
||||
var configuration = project.Configurations.First();
|
||||
foreach (var e in project.Configurations)
|
||||
{
|
||||
if (e.Configuration == defaultConfiguration && e.Target == defaultTarget && e.Platform == Platform.BuildTargetPlatform)
|
||||
{
|
||||
configuration = e;
|
||||
break;
|
||||
}
|
||||
}
|
||||
var defines = string.Join(";", project.Defines);
|
||||
if (configuration.TargetBuildOptions.ScriptingAPI.Defines.Count != 0)
|
||||
{
|
||||
if (defines.Length != 0)
|
||||
defines += ";";
|
||||
defines += string.Join(";", configuration.TargetBuildOptions.ScriptingAPI.Defines);
|
||||
}
|
||||
var outputPath = Utilities.MakePathRelativeTo(project.CSharp.OutputPath ?? configuration.TargetBuildOptions.OutputFolder, projectDirectory);
|
||||
var intermediateOutputPath = Utilities.MakePathRelativeTo(project.CSharp.IntermediateOutputPath ?? Path.Combine(configuration.TargetBuildOptions.IntermediateFolder, "CSharp"), projectDirectory);
|
||||
|
||||
csProjectFileContent.AppendLine(string.Format(" <PropertyGroup Condition=\" '$(Configuration)|$(Platform)' == '{0}|{1}' \">", defaultConfiguration, defaultArchitecture));
|
||||
csProjectFileContent.AppendLine(" <DebugSymbols>true</DebugSymbols>");
|
||||
csProjectFileContent.AppendLine(" <DebugType>portable</DebugType>");
|
||||
csProjectFileContent.AppendLine(string.Format(" <Optimize>{0}</Optimize>", defaultConfiguration == TargetConfiguration.Debug ? "false" : "true"));
|
||||
csProjectFileContent.AppendLine(string.Format(" <OutputPath>{0}\\</OutputPath>", outputPath));
|
||||
csProjectFileContent.AppendLine(string.Format(" <BaseIntermediateOutputPath>{0}\\</BaseIntermediateOutputPath>", intermediateOutputPath));
|
||||
csProjectFileContent.AppendLine(string.Format(" <IntermediateOutputPath>{0}\\</IntermediateOutputPath>", intermediateOutputPath));
|
||||
csProjectFileContent.AppendLine(string.Format(" <DefineConstants>{0}</DefineConstants>", defines));
|
||||
csProjectFileContent.AppendLine(" <ErrorReport>prompt</ErrorReport>");
|
||||
csProjectFileContent.AppendLine(" <WarningLevel>4</WarningLevel>");
|
||||
csProjectFileContent.AppendLine(" <AllowUnsafeBlocks>true</AllowUnsafeBlocks>");
|
||||
if (configuration.TargetBuildOptions.ScriptingAPI.IgnoreMissingDocumentationWarnings)
|
||||
csProjectFileContent.AppendLine(" <NoWarn>1591</NoWarn>");
|
||||
csProjectFileContent.AppendLine(string.Format(" <DocumentationFile>{0}\\{1}.CSharp.xml</DocumentationFile>", outputPath, project.Name));
|
||||
csProjectFileContent.AppendLine(" <UseVSHostingProcess>true</UseVSHostingProcess>");
|
||||
csProjectFileContent.AppendLine(" </PropertyGroup>");
|
||||
}
|
||||
|
||||
// Configurations
|
||||
foreach (var configuration in project.Configurations)
|
||||
{
|
||||
var defines = string.Join(";", project.Defines);
|
||||
if (configuration.TargetBuildOptions.ScriptingAPI.Defines.Count != 0)
|
||||
{
|
||||
if (defines.Length != 0)
|
||||
defines += ";";
|
||||
defines += string.Join(";", configuration.TargetBuildOptions.ScriptingAPI.Defines);
|
||||
}
|
||||
var outputPath = Utilities.MakePathRelativeTo(project.CSharp.OutputPath ?? configuration.TargetBuildOptions.OutputFolder, projectDirectory);
|
||||
var intermediateOutputPath = Utilities.MakePathRelativeTo(project.CSharp.IntermediateOutputPath ?? Path.Combine(configuration.TargetBuildOptions.IntermediateFolder, "CSharp"), projectDirectory);
|
||||
|
||||
csProjectFileContent.AppendLine(string.Format(" <PropertyGroup Condition=\"'$(Configuration)|$(Platform)' == '{0}' or '$(Configuration)|$(Platform)' == '{1}'\">", configuration.Name, configuration.Name.Replace(configuration.ArchitectureName, "AnyCPU")));
|
||||
csProjectFileContent.AppendLine(" <DebugSymbols>true</DebugSymbols>");
|
||||
csProjectFileContent.AppendLine(" <DebugType>portable</DebugType>");
|
||||
csProjectFileContent.AppendLine(string.Format(" <Optimize>{0}</Optimize>", configuration.Configuration == TargetConfiguration.Debug ? "false" : "true"));
|
||||
csProjectFileContent.AppendLine(string.Format(" <OutputPath>{0}\\</OutputPath>", outputPath));
|
||||
csProjectFileContent.AppendLine(string.Format(" <BaseIntermediateOutputPath>{0}\\</BaseIntermediateOutputPath>", intermediateOutputPath));
|
||||
csProjectFileContent.AppendLine(string.Format(" <IntermediateOutputPath>{0}\\</IntermediateOutputPath>", intermediateOutputPath));
|
||||
csProjectFileContent.AppendLine(string.Format(" <DefineConstants>{0}</DefineConstants>", defines));
|
||||
csProjectFileContent.AppendLine(" <ErrorReport>prompt</ErrorReport>");
|
||||
csProjectFileContent.AppendLine(" <WarningLevel>4</WarningLevel>");
|
||||
csProjectFileContent.AppendLine(" <AllowUnsafeBlocks>true</AllowUnsafeBlocks>");
|
||||
if (configuration.TargetBuildOptions.ScriptingAPI.IgnoreMissingDocumentationWarnings)
|
||||
csProjectFileContent.AppendLine(" <NoWarn>1591</NoWarn>");
|
||||
csProjectFileContent.AppendLine(string.Format(" <DocumentationFile>{0}\\{1}.CSharp.xml</DocumentationFile>", outputPath, project.Name));
|
||||
csProjectFileContent.AppendLine(" <UseVSHostingProcess>true</UseVSHostingProcess>");
|
||||
csProjectFileContent.AppendLine(" </PropertyGroup>");
|
||||
}
|
||||
|
||||
// Nuget Package References
|
||||
csProjectFileContent.AppendLine(" <ItemGroup>");
|
||||
csProjectFileContent.AppendLine(" <PackageReference Include=\"DotNetZip\" Version=\"1.16.0\" />");
|
||||
csProjectFileContent.AppendLine(" <PackageReference Include=\"Microsoft.CodeAnalysis.CSharp\" Version=\"4.3.0-2.final\" />");
|
||||
csProjectFileContent.AppendLine(" <PackageReference Include=\"Microsoft.VisualStudio.Setup.Configuration.Interop\" Version=\"3.2.2146\" />");
|
||||
csProjectFileContent.AppendLine(" <PackageReference Include=\"Microsoft.Windows.Compatibility\" Version=\"6.0.0\" />");
|
||||
csProjectFileContent.AppendLine(" <PackageReference Include=\"Newtonsoft.Json\" Version=\"13.0.2-beta1\" />");
|
||||
csProjectFileContent.AppendLine(" <PackageReference Include=\"System.CodeDom\" Version=\"6.0.2-mauipre.1.22102.15\" />");
|
||||
csProjectFileContent.AppendLine(" </ItemGroup>");
|
||||
|
||||
// References
|
||||
|
||||
csProjectFileContent.AppendLine(" <ItemGroup>");
|
||||
|
||||
foreach (var reference in project.CSharp.SystemReferences)
|
||||
{
|
||||
csProjectFileContent.AppendLine(string.Format(" <Reference Include=\"{0}\" />", reference));
|
||||
}
|
||||
|
||||
foreach (var reference in project.CSharp.FileReferences)
|
||||
{
|
||||
csProjectFileContent.AppendLine(string.Format(" <Reference Include=\"{0}\">", Path.GetFileNameWithoutExtension(reference)));
|
||||
csProjectFileContent.AppendLine(string.Format(" <HintPath>{0}</HintPath>", Utilities.MakePathRelativeTo(reference, projectDirectory)));
|
||||
csProjectFileContent.AppendLine(" </Reference>");
|
||||
}
|
||||
|
||||
foreach (var dependency in project.Dependencies)
|
||||
{
|
||||
csProjectFileContent.AppendLine(string.Format(" <ProjectReference Include=\"{0}\">", Utilities.MakePathRelativeTo(dependency.Path, projectDirectory)));
|
||||
csProjectFileContent.AppendLine(string.Format(" <Project>{0}</Project>", ((VisualStudioProject)dependency).ProjectGuid.ToString("B").ToUpperInvariant()));
|
||||
csProjectFileContent.AppendLine(string.Format(" <Name>{0}</Name>", dependency.Name));
|
||||
csProjectFileContent.AppendLine(" </ProjectReference>");
|
||||
}
|
||||
|
||||
csProjectFileContent.AppendLine(" </ItemGroup>");
|
||||
|
||||
// Files and folders
|
||||
|
||||
csProjectFileContent.AppendLine(" <ItemGroup>");
|
||||
|
||||
var files = new List<string>();
|
||||
if (project.SourceFiles != null)
|
||||
files.AddRange(project.SourceFiles);
|
||||
if (project.SourceDirectories != null)
|
||||
{
|
||||
foreach (var folder in project.SourceDirectories)
|
||||
{
|
||||
files.AddRange(Directory.GetFiles(folder, "*", SearchOption.AllDirectories));
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var file in files)
|
||||
{
|
||||
string fileType;
|
||||
if (file.EndsWith(".cs", StringComparison.OrdinalIgnoreCase))
|
||||
fileType = "Compile";
|
||||
else
|
||||
fileType = "None";
|
||||
|
||||
var projectPath = Utilities.MakePathRelativeTo(file, projectDirectory);
|
||||
csProjectFileContent.AppendLine(string.Format(" <{0} Include=\"{1}\" />", fileType, projectPath));
|
||||
}
|
||||
|
||||
if (project.GeneratedSourceFiles != null)
|
||||
{
|
||||
foreach (var file in project.GeneratedSourceFiles)
|
||||
{
|
||||
string fileType;
|
||||
if (file.EndsWith(".cs", StringComparison.OrdinalIgnoreCase))
|
||||
fileType = "Compile";
|
||||
else
|
||||
fileType = "None";
|
||||
|
||||
csProjectFileContent.AppendLine(string.Format(" <{0} Visible=\"false\" Include=\"{1}\" />", fileType, file));
|
||||
}
|
||||
}
|
||||
|
||||
csProjectFileContent.AppendLine(" </ItemGroup>");
|
||||
|
||||
// End
|
||||
|
||||
//csProjectFileContent.AppendLine(" <Import Project=\"$(MSBuildToolsPath)\\Microsoft.CSharp.targets\" />");
|
||||
csProjectFileContent.AppendLine("</Project>");
|
||||
|
||||
if (defaultTarget.CustomExternalProjectFilePath == null)
|
||||
{
|
||||
// Save the files
|
||||
Utilities.WriteFileIfChanged(project.Path, csProjectFileContent.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using Flax.Build.Platforms;
|
||||
using Microsoft.VisualStudio.Setup.Configuration;
|
||||
using Task = Flax.Build.Graph.Task;
|
||||
|
||||
namespace Flax.Build.Projects.VisualStudio
|
||||
{
|
||||
|
||||
@@ -31,6 +31,7 @@ namespace Flax.Build.Projects.VisualStudio
|
||||
{
|
||||
case TargetType.NativeCpp: return VisualStudioProjectGenerator.ProjectTypeGuids.WindowsVisualCpp;
|
||||
case TargetType.DotNet: return VisualStudioProjectGenerator.ProjectTypeGuids.WindowsCSharp;
|
||||
case TargetType.DotNetCore: return VisualStudioProjectGenerator.ProjectTypeGuids.WindowsCSharp;
|
||||
default: throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -428,7 +428,7 @@ namespace Flax.Build.Projects.VisualStudioCode
|
||||
}
|
||||
}
|
||||
// C# project
|
||||
else if (project.Type == TargetType.DotNet)
|
||||
else if (project.Type == TargetType.DotNet || project.Type == TargetType.DotNetCore)
|
||||
{
|
||||
foreach (var configuration in project.Configurations)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user