Skip to content

Commit

Permalink
Visual studio plugin improvement
Browse files Browse the repository at this point in the history
Initial support for dotnet CLI tool
  • Loading branch information
zapov committed Oct 18, 2018
1 parent f44c1bb commit f2a3ed8
Show file tree
Hide file tree
Showing 16 changed files with 319 additions and 235 deletions.
71 changes: 71 additions & 0 deletions VisualStudioPlugin/Compiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,77 @@ public static string TempPath
}
}

private static readonly char[] InvalidFileChars = Path.GetInvalidFileNameChars();

public static string BuildDotnet(string project, string output, Dictionary<string, string> dependencies, Dictionary<string, string> files)
{
var folder = Path.Combine(TempPath, project);
if (!Directory.Exists(folder))
Directory.CreateDirectory(folder);
else
{
foreach (var f in Directory.GetFiles(folder, "*.cs"))
File.Delete(f);
}
var outputName = output.IndexOf('/') == -1 ? output : output.Substring(output.LastIndexOf('/'));
var csproj = new StringBuilder(@"<Project Sdk=""Microsoft.NET.Sdk"">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<AssemblyName>");
csproj.Append(outputName);
csproj.Append(@"</AssemblyName>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
</PropertyGroup>");
if (dependencies.Count != 0)
{
csproj.Append(@"
<ItemGroup>");
foreach (var kv in dependencies)
{
csproj.AppendFormat(@"
<PackageReference Include=""{0}"" Version=""{1}"" />", kv.Key, kv.Value);
}
csproj.Append(@"
</ItemGroup>
");
}
csproj.Append(@"
</Project>");
File.WriteAllText(Path.Combine(folder, project + ".csproj"), csproj.ToString());
foreach (var kv in files)
{
var name = kv.Key;
if (name.IndexOfAny(InvalidFileChars) != -1)
{
foreach (var ch in InvalidFileChars)
name = name.Replace(ch, '_');
}
File.WriteAllText(Path.Combine(folder, name + ".cs"), kv.Value);
}
var si = new ProcessStartInfo
{
FileName = "dotnet",
WorkingDirectory = folder,
Arguments = "build -c Release",
UseShellExecute = false
};
si.EnvironmentVariables["DOTNET_CLI_TELEMETRY_OPTOUT"] = "1";
var process = Process.Start(si);
try
{
process.WaitForExit();
if (process.ExitCode == 0)
return Path.Combine(Path.Combine(Path.Combine(folder, "bin"), "Release"), outputName + ".dll");
Process.Start(folder);
throw new ApplicationException(@"Error during compilation. Try running the project manually");
}
finally
{
process.Dispose();
}
}

public static string GenerateAssembly(
string assemblyPath,
string[] sources,
Expand Down
9 changes: 1 addition & 8 deletions VisualStudioPlugin/DDDLanguage.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
<Compile Include="Classification\DddClassifierProvider.cs" />
<Compile Include="Classification\DslClassifierProvider.cs" />
<Compile Include="ChunkedMemoryStream.cs" />
<Compile Include="Gui\BuildTypes.cs" />
<Compile Include="Gui\CompileTargets.cs" />
<Compile Include="Gui\DatabaseInfo.cs" />
<Compile Include="Gui\View\ConfigurationOracleControl.xaml.cs">
Expand Down Expand Up @@ -208,14 +209,6 @@
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<Content Include="catalog.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<IncludeInVSIX>true</IncludeInVSIX>
</Content>
<Content Include="manifest.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<IncludeInVSIX>true</IncludeInVSIX>
</Content>
<None Include="source.extension.vsixmanifest">
<SubType>Designer</SubType>
</None>
Expand Down
27 changes: 17 additions & 10 deletions VisualStudioPlugin/DDDLanguagePackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,10 @@ private void ReadInfo(DatabaseInfo info, IPropertyBag pBag)
private void ReadInfo(LibraryInfo info, IPropertyBag pBag)
{
info.CompileOption = TryReadBool(info.Type + ".Compile", pBag);
if (!info.SourceOnly)
string buildType = TryReadString(info.Type + ".BuildType", pBag);
if (!string.IsNullOrEmpty(buildType))
info.BuildType = (BuildTypes)Enum.Parse(typeof(BuildTypes), buildType);
if (info.BuildType != BuildTypes.Source)
info.Name = TryReadString(info.Type + ".Name", pBag) ?? info.Name;
info.Target = TryReadString(info.Type + ".Target", pBag) ?? info.Target;
info.Dependencies = TryReadString(info.Type + ".Dependencies", pBag) ?? info.Dependencies;
Expand Down Expand Up @@ -289,15 +292,19 @@ private void WriteInfo(DatabaseInfo info, IPropertyBag pBag)
}
}

private void WriteInfo(LibraryInfo info, IPropertyBag pBag)
private void WriteInfo(LibraryInfo info, LibraryInfo reference, IPropertyBag pBag)
{
var reference = new LibraryInfo(info.Type, null, info.RequireDependencies, null);
object val;
if (reference.CompileOption != info.CompileOption)
{
val = info.CompileOption.ToString();
pBag.Write(info.Type + ".Compile", ref val);
}
if (reference.BuildType != info.BuildType)
{
val = info.BuildType.ToString();
pBag.Write(info.Type + ".BuildType", ref val);
}
if (reference.Name != info.Name)
{
val = info.Name;
Expand Down Expand Up @@ -370,13 +377,13 @@ public int WriteSolutionProps(IVsHierarchy pHierarchy, string pszKey, IPropertyB
{
WriteInfo(Presenter.PostgresDb, pPropBag);
WriteInfo(Presenter.OracleDb, pPropBag);
WriteInfo(Presenter.PocoLibrary, pPropBag);
WriteInfo(Presenter.ClientLibrary, pPropBag);
WriteInfo(Presenter.PortableLibrary, pPropBag);
WriteInfo(Presenter.PhpLibrary, pPropBag);
WriteInfo(Presenter.WpfLibrary, pPropBag);
WriteInfo(Presenter.PostgresLibrary, pPropBag);
WriteInfo(Presenter.OracleLibrary, pPropBag);
WriteInfo(Presenter.PocoLibrary, CompileTargets.PocoLibraryDefault, pPropBag);
WriteInfo(Presenter.ClientLibrary, CompileTargets.ClientLibraryDefault, pPropBag);
WriteInfo(Presenter.PortableLibrary, CompileTargets.PortableLibraryDefault, pPropBag);
WriteInfo(Presenter.PhpLibrary, CompileTargets.PhpSourceDefault, pPropBag);
WriteInfo(Presenter.WpfLibrary, CompileTargets.WpfLibraryDefault, pPropBag);
WriteInfo(Presenter.PostgresLibrary, CompileTargets.PostgresLibraryDefault, pPropBag);
WriteInfo(Presenter.OracleLibrary, CompileTargets.OracleLibraryDefault, pPropBag);
}
catch
{
Expand Down
9 changes: 9 additions & 0 deletions VisualStudioPlugin/Gui/BuildTypes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace DDDLanguage
{
public enum BuildTypes
{
LegacyDotNet,
Source,
DotNetStandard
}
}
Loading

0 comments on commit f2a3ed8

Please sign in to comment.