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

NetCore: Error on Solution Rebuild in Visual Studio 2022 #10760

Closed
idseefeld opened this issue Jul 28, 2021 · 10 comments
Closed

NetCore: Error on Solution Rebuild in Visual Studio 2022 #10760

idseefeld opened this issue Jul 28, 2021 · 10 comments

Comments

@idseefeld
Copy link
Contributor

Which exact Umbraco version are you using? For example: 8.13.1 - don't just write v8

v9-RC

Bug summary

What I did

I am testing Visual Studio 2022 Community Preview edition and have a solution with a .Net 5 MVC Website project depending on a class library project.
Command combination of Clean and Build solution works.
Using just Rebuild fails with:

  • rzc generate exited with code 1.
  • Umbraco9ModelsBuilderSample.Web (website project)
  • C:\Program Files\dotnet\sdk\6.0.100-preview.6.21355.2\Sdks\Microsoft.NET.Sdk.Razor\build\netstandard2.0\Microsoft.NET.Sdk.Razor.CodeGeneration.targets

You may clone repo https://github.com/idseefeld/Umbraco9ModelsBuilderSample to reproduce the issue.
The issue might be related to this solutions specifics, but in Visual Studio 2019 Community edition Rebuild works.


Microsoft response

This issue seems to be caused by Umbraco (particularly the Umbraco.StaticAssets package) are built and not Visual Studio or the .NET Core SDK. We recommend filing an issue at their project site: https://github.com/umbraco/Umbraco-CMS. For more information, see also our issue reporting guidelines.


🙄Any idea?

Kind regards,
Dirk

Specifics

Please find Microsoft issue report here: https://developercommunity.visualstudio.com/t/error-on-solution-rebuild-in-visual-studio-2022/1477291

Steps to reproduce

v9-rebuild-issue-vs2022-preview

Expected result / actual result

In Visual Studio 2019 Community edition Rebuild Solution works.

@nul800sebastiaan
Copy link
Member

I think it would be best to use our templates to set up a project, open the csproj in VS and when saving it put the solution file somewhere (it will ask you where to put it). Like in v8, we advise you not to use the default MVC template, in v9, we advise you to use the Umbraco template. We are aware that the template doesn't get installed in VS2022 Preview for now so we recommend setting your solutions up in VS2019 stable :)

As it turns out, with your setup in your csproj you have:

    <PropertyGroup>
        <RazorCompileOnBuild>true</RazorCompileOnBuild>
    </PropertyGroup>

Whereas the default if you use the .NET template would be:

    <PropertyGroup>
        <RazorCompileOnBuild>false</RazorCompileOnBuild>
        <RazorCompileOnPublish>false</RazorCompileOnPublish>
    </PropertyGroup>

There's no need to compile razor, which is probably why there's too much being compiled.

However, correcting this has led to another error on rebuild:

Severity	Code	Description	Project	File	Line	Suppression State
Error	MSB3030	Could not copy the file "D:\Temp\Umbraco9ModelsBuilderSample-main\Umbraco9ModelsBuilderSample.Web\umbraco\config\appsettings-schema.json" because it was not found.	Umbraco9ModelsBuilderSample.Web	C:\Program Files\Microsoft Visual Studio\2022\Preview\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets	4964	

Mostly, I would ask why the need to rebuild at all, a rebuild is hardly ever necessary. I know a lot of people are used to doing it for unknown reasons but a regular build is enough 99,999999% of the time. That is a scientific number, yes! 😉

Anyway, a build after a rebuild with the appsettings-schema.json error works just fine. I would recommend sticking to not use rebuild for now and it would be great to investigate why the appsettings-schema.json is there.

I'm sure it SHOULD be possible to compile razor files as well and it would be great to investigate how to fix the original error reported as well.

@umbrabot
Copy link

Hi @idseefeld,

We're writing to let you know that we would love some help with this issue. We feel that this issue is ideal to flag for a community member to work on it. Once flagged here, folk looking for issues to work on will know to look at yours. Of course, please feel free work on this yourself ;-). If there are any changes to this status, we'll be sure to let you know.

For more information about issues and states, have a look at this blog post

Thanks muchly, from your friendly Umbraco GitHub bot :-)

@idseefeld
Copy link
Contributor Author

@nul800sebastiaan interestingly the following solved the issue:

<PropertyGroup>
        <RazorCompileOnBuild>true</RazorCompileOnBuild>
        <RazorCompileOnPublish>true</RazorCompileOnPublish>
</PropertyGroup>

Uups, actually I should have known about the extra line, as I have reported the publish issue.

Razor build in this case might be okay(?), because my configuration for ModelsBuilder extracts the models into a folder of the .Core project (see appSettings.Development.json):

"Umbraco": {
    "CMS": {
      "ModelsBuilder": {
        "ModelsDirectory": "~/../Umbraco9ModelsBuilderSample.Core/UmbracoModels",
        "AcceptUnsafeModelsDirectory": true,
        "ModelsMode": "SourceCodeManual"
      },

My understanding here is, that this is the best way to avoid circular dependencies.
Whatsoever, setting the value to true fixes your issue 😁

Btw. I did not use VS2022 to create the solution. I have just opened it later on and tried out building times, which probably was the reason for finding the issue😜 (I know you have written about the Rebuild topic in 24days or so and I agree although I am not aware of the exact difference between the combination of Clear & Build vs Rebuild🤔)
Ähm, and shame on me, I admit that frustration and confusion😵 about a broken build lets me try out these kind of helpless actions.🤫🤭

Nevertheless there must be differences in the behaviour of VS2019 vs VS2022 as my example clearly shows. So from my point of view their comment is wrong. 🙄

Finally I close the issue!

@idseefeld idseefeld reopened this Jul 29, 2021
@idseefeld
Copy link
Contributor Author

@nul800sebastiaan Sorry, I have reopen this again.
I am not sure what happend:

  1. After my last comment I updated VS2022 (Version 17.0.0 Preview 2.1)
  2. The error on Rebuild appears again 😪

Maybe I have used VS2019 and not VS2022 as the Rebuild seems to work🤪

Would be nice if someone could verify with the previous VS2022...

Or we take your advice for now and do not use Rebuild. In the end VS2022 is still in preview🙄

@idseefeld
Copy link
Contributor Author

Just found another hint:
If you execute Clean Solution before Rebuild Solution you get no error.
I see a lot of files get deleted during Clean Solution. These are not only DLLs (as usual?). Has this to do with the new template approach?
Okay, I need to read the docs...

@bergmania
Copy link
Member

bergmania commented Aug 5, 2021

Just found another hint:
If you execute Clean Solution before Rebuild Solution you get no error.
I see a lot of files get deleted during Clean Solution. These are not only DLLs (as usual?). Has this to do with the new template approach?
Okay, I need to read the docs...

We clean up files on clean, and add files (if missing) on build. This all happens in the targets file from the nuget package: https://github.com/umbraco/Umbraco-CMS/blob/v9/dev/build/NuSpecs/build/Umbraco.Cms.StaticAssets.targets

@jaddie
Copy link
Contributor

jaddie commented Aug 26, 2021

Just to chime into this, I am using the razor compile on build & publish, I've also found odd behaviour at one point if you have one on & not the other, but my models are in a separate compiled destination hence my use of it. Not to mention if this is not enabled, then the site can break when deployed due to Umbraco generating its own files & then there being ambiguous references etc.

Also I find that Umbraco is quite a lot faster when the razor files are compiled into the solution, presumably because they are not being re-compiled when the site starts up anymore etc. Just watch out that you have both set to true, otherwise Umbraco itself gets upset and starts breaking at times as well (when using dotnet publish) which I now have a setup whereby I am deploying a whole Umbraco site just by using dotnet publish on & pushing it to a build server which then deploys the output zip to a folder & it works without a hitch now.

@bachratyg
Copy link

Just looking at the source this looks like Clean/Rebuild would wipe out ALL assets in the umbraco folders. E.g. if I have a custom language file in umbraco\config\lang it would also be removed. Is this intentional?

@nul800sebastiaan
Copy link
Member

@bachratyg Yes, the files in ~\umbraco\config\lang will be overwritten on build so don't change them.

You can put custom language files in ~\config\lang\lang.user.xml instead. Any keys you put in there will also override the default language keys that come with Umbraco.

And example of overriding an existing language can be found here: #11345 (comment)

And if you have your own language file. let's say for Ukranian, I believe you would start a new file ~\config\lang\ua.user.xml and that should work.

@nul800sebastiaan
Copy link
Member

I just realized that this specific issue has been fixed in #11216 for the 9.0.1 release tomorrow, I'll close this one as fixed!

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

6 participants