MSBUILD publish does not publish a xsd schema file - msbuild

I am using MSbuild to publish my webservices projects on the command line using the following
command:
msbuild.exe MyWebservicesProjectPath\Services.csproj /t:ResolveReferences;_CopyWebApplication /p:Configuration=Release;BuildingProject=true;WebProjectOutputDir=c:\inetpub\wwwroot\webserviceDest;OutDir=c:\inetpub\wwwroot\webserviceDest\
Everything publishes fine except for .xsd files that are located in ProjectName\WebServices\Schema folder.
what's happening here?
Thanks.

In your solution check the property of your .xsd file.
The default setting of this type of artifact for the "Copy to Output Directory" is "Do Not Copy".
Setting this to "Copy always" (or "Copy if newer") should fix your problem.
Project file sample
<ItemGroup>
<None Include="XMLSchema1.xsd">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

In the solution explorer right click on .XSD file -> click Properties and change Build Action to "Content" under Advanced section.

Related

How to restore only a specific solution folder with an MSBuild command

I have more than hundred projects in two solution folders.
How can I build a specific solution folder with the msbuild command in CLI, like the same thing in Visual Studio with right click on a specific solution folder and click on Build?
I use Visual Studio 2019 16.8.3
Update:
I found the Build a solution folder with MSBuild Stack Overflow question, but as you can see in this question, anyone does not provide a built-in solution for restore or build or any other target run in a specific solution folder. I hope to find a way to run the target on a specific solution folder with a built-in way using MSBuild.
Just open Developer Command Prompt for Visual Studio and then type these to build the specific .sln file like this:
msbuild xxx\xxx.sln -t:build -p:Configuration=Debug
The solution folder from Solution Explorer is a virtual folder for the Visual Studio IDE. If you want to use an MSBuild command line, you have to create such a real folder. Otherwise, there isn't any such way.
1) Open Solution Explorer → Switch View, create a real folder (on my side, it is called test), and then drag the related projects into the folder.
2) create a file called test.proj on the solution folder. And then add these on that file:
<Project>
<ItemGroup>
<File Include="test\**\*.csproj"/>
</ItemGroup>
<Target Name="Build">
<MSBuild Projects="#(File)" Targets="Build"/>
</Target>
</Project>
3) use command line msbuild test.proj to get what you want.

Can i use the "app_code" folder in .net core?

Is the app_code folder used in asp.net also available in net. core?
If I can't use it, is there any other way I can compile it into folders at runtime?
You can name the folder as "app_code" in .net core application.
If you want to copy the "app_code" folder when publish the application, try to set the file's "CopyToPublishDirectory" property to "Always" (open the app_code folder, right click the file and select the "Properties" option, then change the "CopyToPublishDirectory" property to "Always").
Besides, you could also change the property's value from the applicaion .csproj file, using the following code:
<ItemGroup>
<Compile Update="app_core\testclass.cs">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Compile>
</ItemGroup>

Visual studio 2017 and nuget package

I am creating nuget package which should contain also config file. Problem is that if I want to use csproj for nuget package definition, I don't know how to specify that config file should be copied and "copy to output directory" on file set when package is being installed.
https://learn.microsoft.com/en-us/nuget/guides/create-net-standard-packages-vs2017
Previously I used nuspec and for install.ps1.
Thanks
(https://learn.microsoft.com/en-us/nuget/guides/create-net-standard-packages-vs2017)
To include a file, you need to add / modify an update item for the file. If you have set "copy to output directory" to "preserve newest", you might already have one in the csproj file. To include this file into the resulting nuget package, you need to set the Pack="true" metadata:
<ItemGroup>
<None Update="config.txt" CopyToOutputDirectory="PreserveNewest" Pack="true" />
</ItemGroup>
Note that depending on your project type (=> web sdk or "normal" sdk is being used) you may see different item types (None, Content) for files.

Weird behavior with $(SolutionDir) with msbuild in a .csproj file being wrong

I have a .sln solution file that references a .csproj project file that has an after build task of something like:
<PropertyGroup>
<PostBuildEvent>
xcopy $(SolutionDir)\dir1\Somefle.xml $(ProjectDir) /Y /I
</PostBuildEvent>
</PropertyGroup>
The solution is built using msbuild with a task like the following:
<Target Name="CompileSolution">
<MSBuild Projects="#(SolutionToBuild)" Targets="Rebuild" Properties="Platform=Any CPU" />
</Target>
Now here's the strange part:
If I:
run the build script (say c:\MyWorkingCopy)
rename the working copy folder (say to c:\YourWorkingCopy)
run the build script again
On step 3, the xcopy will fail, because it will because it will be trying to copy the file from "c:\MyWorkingCopy" - which of course is not where the solution file now resides.
Why does msbuild use the old Solution directory? And is there some way to reset it?
(I am using .NET Framework 3.5)
It may be related to the sln.cache file that is created by msbuild when you build a sln file (it's a temporary proj file built from the sln one), if it is present or if the sln is not modified the sln.cache file may be used... I don't really know but it I think it could help.

How do I add an MSBuild .proj file to my solution?

Does anyone know how to add a an MSBuild .proj file to my solution?
I was just given existing code from a vendor with a solution that references an MSBuild .proj file as one of its projects. When I open the solution, the project shows as (unavailable). It appears that I need to install some sort of project template to get this project to open correctly. I installed the Codeplex MSBuild Template, but this doesn't appear to be it.
Any ideas?
If you don't need IDE support, it's possible to do this using MSBuild solution extension targets.
Create a file named "before.SolutionName.sln.targets" with the following code:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<ProjectReference Include="CustomProject\CustomProject.proj">
<AdditionalProperties>Configuration=$(Configuration); Platform=AnyCPU</AdditionalProperties>
<Configuration>$(Configuration)</Configuration>
<Platform>AnyCPU</Platform>
</ProjectReference>
</ItemGroup>
</Project>
When your solution is built at command line by MSBuild (ie/ build server) the custom MSBuild project will be pulled into the temporary in-memory project file that MSBuild converts the solution into.
I actually got it to work! I re-started Visual Studio and still saw that the projects were unavailable after installing the MSBuild Template mentioned above. I had to manually reload the projects. That fixed the issue.