You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm migrating some of our legacy deployment processes for a WebForms app. Our current deployment procedure is to just copy the entire projects folder after build, which ends up including a ton of unnecessary files (such as the .cs files themselves) in the result, and doesn't support the XML transformation step that happens only on publish.
I'm now switching into a more standard approach, where we first publish our project using the /p:DeployOnBuild=true MSBuild setting, and then grab the output from that.
Because of this change, I need to make sure that all the "content" files (images, javascript, css, etc) in the project are properly considered as Content in MSBuild and subsequently copied to the publish folder.
To achieve this, I took a look at how the standard files are added in the SDK, and tried to do something similar for my own needs.
I'd like to check if this is a good approach to the problem. It appears to work just fine, but I'm no MSBuild expert and was wondering if there is a simpler way to achieve the same results.
It looks verbose to me and has some duplication, but it seems better than individually marking each and every content file as Content in Visual Studio.
I don't think you need the DefaultItemExcludesPropertyGroup at all.
I think the ContentExclude should be $(DefaultItemExcludes) not $(DefaultWebFormsItemExcludes) - this prevents it picking up content from folders like node_modules etc. - see #19
Generally look at the SDK project documentation on globbing etc. as it should all work the same as a modern csproj (or vbproj).
Each project is different, so I can't really advise other than if you have specific issues.
And do you really want to include *.pdn files? Your site publishes Paint.Net files as content?
Remember you will need to either resigister them as static files and add a mime-type, or if they are converted using a handler, register an appropriate handler. If you have contect in e.g. App_Data you can just
I don't think you need the DefaultItemExcludesPropertyGroup at all.
Aren't the files added to the None build action otherwise? If I manually change a file in the project to Content, Visual Studio adds a <None Remove and a <Content Include tag for that item. I thought the DefaultItemExcludes was doing that part of the work (removing from None).
If you could elaborate a bit on how this works that would be appreciated. Another reason I did it this way is because this is how it is setup for the webforms files in the SDK:
I think the ContentExclude should be $(DefaultItemExcludes) not $(DefaultWebFormsItemExcludes) - this prevents it picking up content from folders like node_modules etc. - see #19 Generally look at the SDK project documentation on globbing etc. as it should all work the same as a modern csproj (or vbproj).
That was again based on the SDK code. I thought I was doing conceptually the same thing, so I just copied the same approach from there:
And do you really want to include *.pdn files? Your site publishes Paint.Net files as content? Remember you will need to either resigister them as static files and add a mime-type, or if they are converted using a handler, register an appropriate handler.
I was surprised when I saw that file extension on WinDiff as well when double checking my publish pipeline 😅. We have one of those in one of our "Images" folder. I've since removed it from that list and added the whole "Images" folder as content (along with a few others).
Yeah I realized this after posting the question. I changed the approach slightly to explicitly mark some folders as content, and kept only generic extensions that would appear almost everywhere in the list. Something like:
There are quite a few nuances here - but it looks like what you have is working for you so I would go with it.
The DefaultWebFormsItemExcludes prevents it picking up items copied to obj/ and bin/ - e.g. published files as well as files from package managers.
It shouldn't normally matter that an item is in None and Content, hence the bit about DefaultItemExcludes.
As @CZEMacLeod mentions there are a few nuances to how the ItemGroups work, and I am hesitant to steer you away from something that is doing what you need to do, but I will share this as a potential starting point for your adventures/experiments in ItemGroups
<ItemGroup>
<None Remove="**/*"
Label="Remove all files from the None ItemGroup, since we are going to have most things be content" />
<Content Include="**/*"
Exclude="$(DefaultItemExcludes);
$(DefaultExcludesInProjectFolder);
$(AppDesignerFolder)/**/*;
**/*$(DefaultLanguageSourceExtension);
**/*.resx"
Label="Add Most Items under the project to the Content ItemGroup except compile files, resx files, and files under the bin, obj, and 'Properties/MyProject' directories"/>
<None Include="$(AppDesignerFolder)/**/*"
Exclude="$(DefaultItemExcludes);
$(DefaultExcludesInProjectFolder);
**/*$(DefaultLanguageSourceExtension);
**/*.resx"
Label="Add back to the None ItemGroup the items from the 'Properties/MyProject' directory " />
</ItemGroup>
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
I'm migrating some of our legacy deployment processes for a WebForms app. Our current deployment procedure is to just copy the entire projects folder after build, which ends up including a ton of unnecessary files (such as the
.csfiles themselves) in the result, and doesn't support the XML transformation step that happens only on publish.I'm now switching into a more standard approach, where we first publish our project using the
/p:DeployOnBuild=trueMSBuild setting, and then grab the output from that.Because of this change, I need to make sure that all the "content" files (images, javascript, css, etc) in the project are properly considered as
Contentin MSBuild and subsequently copied to the publish folder.To achieve this, I took a look at how the standard files are added in the SDK, and tried to do something similar for my own needs.
This is what I added to my
csprojfile:I'd like to check if this is a good approach to the problem. It appears to work just fine, but I'm no MSBuild expert and was wondering if there is a simpler way to achieve the same results.
It looks verbose to me and has some duplication, but it seems better than individually marking each and every content file as
Contentin Visual Studio.Any feedback is welcome.
All reactions