Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compile Output Path #68

Closed
byte2pixel opened this issue Dec 13, 2022 · 3 comments
Closed

Compile Output Path #68

byte2pixel opened this issue Dec 13, 2022 · 3 comments

Comments

@byte2pixel
Copy link

This isn't really an issue but more of a question.

I have a C# solution and when I build the solution all the necessary files are in the output path \bin$(Configuration)...

I wrote a CLI using NTypewriter and NTypewriter.CodeModel.Roslyn this CLI takes some arguments like path to the .nt script(s) and path to the cspoj file(s) to render the script(s) against.

Everything works fine, the one issue I have is after running the CLI the assemblies that were in my \bin$(Configuration) folder are all deleted.

My assumption is the project.GetCompilationAsync() is removing the ones that are there, new ones are generated by the CLI. Then when the CLI finishes up everything generated by it is then deleted.

I want to avoid this, by generating stuff in the CLI to some other output path so it doesn't interfere with stuff that was built outside of the CLI. I've been digging and digging but not found a way to get this to work. Is there a way or some other option for me?

Thanks!
Mel

@NeVeSpl
Copy link
Owner

NeVeSpl commented Dec 13, 2022

The problem is well known: phmonte/Buildalyzer#105, unfortunately, I do no see any working solution.

@byte2pixel
Copy link
Author

byte2pixel commented Dec 13, 2022

Thanks for the reply. I've looked through the comments there and there seemed to be some attempts at working around it. One of them, phmonte/Buildalyzer#105 (comment) seems to be the most promising.

However, I didn't have success with it.

@byte2pixel
Copy link
Author

byte2pixel commented Dec 13, 2022

Actually, to follow up I was able to work around this! Using the link you provided and the comment I referenced. I had to remove the two environment options. I'm not sure why adding this argument works, but apparently it causes the "clean" to happen on the temp path instead so the dlls in my real OutputPath are left alone and not deleted! I guess I wouldn't say "Clean" because I removed the "Clean" targets in the options and it still was deleting files. Whatever this is doing though keeps Buildalyzer from deleting the files in my real OutputPath.

I used this to create my AdhocWorkspace:

private static AdhocWorkspace GetAdhocWorkspace(AnalyzerManager manager)
{
    var temp = Path.GetTempPath();
    var list = manager
        .Projects
        .Values
        .Select(p =>
        {
            //Set build/analysis environment options to prevent fighting with IDE, etc...
            var options = new EnvironmentOptions();
            options.Arguments.Add($"/p:OutputPath={Path.Combine(temp, "ba", "bin", p.ProjectGuid.ToString())}");
            return p.Build(options)
                .FirstOrDefault(); //You may not want to do this, may want to omit this and use SelectMany depending on your needs
        })
        .ToList();
    var adhocWorkspace = new AdhocWorkspace();
    foreach (AnalyzerResult analyzerResult in list)
        analyzerResult.AddToWorkspace(adhocWorkspace);
    return adhocWorkspace;
}
AdhocWorkspace workspace = GetAdhocWorkspace(manager);
foreach (var project in workspace.CurrentSolution.Projects)
{
    var compilation = await project.GetCompilationAsync();
   ....
}

@NeVeSpl NeVeSpl closed this as completed Dec 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants