-
Notifications
You must be signed in to change notification settings - Fork 5
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
Creating new ProjectCreator throws FileNotFoundException #95
Comments
Sorry I didn't realize how poorly documented that part of the API is. MSBuildProjectCreator cannot ship with MSBuild assemblies and neither can your application. You will need to have the MSBuild assemblies loaded at runtime. You can do one of the following:
public static class MyApp
{
public static MyApp()
{
AppDomain.CurrentDomain.AssemblyResolve += MSBuildAssemblyResolver.AssemblyResolve;
}
}
|
Alright! I got it working now. Both approaches solved the issue. But inheriting from MSBuildTestBase also removes some environment variables. That's not done in solution 2. Is it not strictly necessary? Or does it become more of an issue when setting it up in CI/CD or something? |
Great! Those environment variables are necessary if your projects end up using the .NET Core SDK and are set by MSBuildLocator as well. |
So, the reason the environment variables are removed in MSBuildTestBase is because the project might also be using MSBuildLocator, or the .NET Core SDK, which would interfere with MSBuildAssemblyResolver? |
There's some magic that will sort of automatically find these paths, and that magic is disabled if the environment variables are set. The options are:
|
I guess I'll go with 2 then :) |
Thanks for reporting this, I've opened #96 to track getting the documentation updated. |
Creating a new ProjectCreator throws a FileNotFoundException at runtime with the following message:
System.IO.FileNotFoundException: 'Could not load file or assembly 'Microsoft.Build, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.'
Steps to reproduce:
<PackageReference Include="MSBuild.ProjectCreation" Version="4.0.1" />
to the project.ProjectCreator.Create();
to Program.Main.I've tried it with a .NET472-project as well, with no success.
The text was updated successfully, but these errors were encountered: