%VSINSTALLDIR% in csproj file - visual-studio

I want to run tools that belong to the VS installation folder from within a .csproj file.
If I run the supplied script:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Auxiliary\Build\vcvars32.bat
then %VSINSTALLDIR% is defined
But inside the .csproj file, it is not defined.
<Target Name="RunNpmGulpBower" AfterTargets="ComputeFilesToPublish">
<!-- As part of publishing, ensure the JS resources are freshly built in production mode -->
<Exec Command="Call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Auxiliary\Build\vcvars32.bat" && npm.cmd install" />
This will not work and bower.cmd will not be found.
Is there any workaround for this?

Related

How to copy dll file from visual studio solution to specific location on drive

I'm making a mod for Red Dead Redemption 2 and I'm trying to use xcopy to copy the dll file from the visual studio folder to my red dead redemption 2 script folder without having to manually move it every time.
A general tool for copying files around - and other things that are not directly supported by Visual Studio - is gulp, which can be integrated into your Visual Studio build.
See: https://www.davepaquette.com/archive/2014/10/08/how-to-use-gulp-in-visual-studio.aspx
Add a post-build step by adding the following element to your .csproj file:
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="copy $(OutDir)$(TargetName).dll C:\DestinationDirectory\$(TargetName).dll /F /Y" />
</Target>

Visual Studio 2017 MSBuild issue

I am trying to publish a Visual stuido Project from another Project, to do this I have created a bat file which runs my MSBuild file. If you run this outside of Visual Studio it works correctly but when i tried to add it to Visual Studio's prebuild scripts it does not publish. I am getting this warning -
C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(1820,5): warning MSB3247: Found confl
icts between different versions of the same dependent assembly. In Visual Studio, double-click this warning (or select
it and press Enter) to fix the conflicts; otherwise, add the following binding redirects to the "runtime" node in the a
pplication configuration file
My MSBuild file:
<Target Name="BeforeBuild">
<MSBuild
Projects="E:\Development\alyz\myAPI\View.API.sln"
Targets="View_API_Search"
Properties="DeployOnBuild=true;Configuration=Release;PublishProfile=InstallerPublish;WebPublishMethod=FileSystem;PublishURL=E:\Temp\installertemp\SearchAPI" />
</Target>
Visual Studio is saying that my project has built correctly but i can't work out why it's not publishing, any ideas?
Visual Studio is saying that my project has built correctly but i can't work out why it's not publishing, any ideas?
You can use another solution for this issue. Following is my publish target, you can check it:
<Target Name="BeforeBuild">
<Exec Command=""<YourMSBuild.exePath>\msbuild.exe" "<YourSolutionPath>\View.API.sln" /p:DeployOnBuild=true /p:PublishProfile=InstallerPublish.pubxml /p:Configuration=Release /p:PublishURL=E:\Temp\installertemp\SearchAPI"></Exec>
</Target>
With this target, the project/solution will be build and published when you build the project.
Hope this helps.

MSBuild 15 WebApplication.targets is missing

I am working with a web application that was written using VS2015, and is being maintained using VS2017. I am trying to write another application to build the full web stack locally using the MSBuild API and other tools. In VS2015 or VS2017 the ASP.NET Web Application project will build successfully, but when running MSBuild programmatically, I keep getting this error:
The imported project "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v15.0\WebApplications\Microsoft.WebApplication.targets" was not found. Confirm that the path in the declaration is correct, and that the file exists on disk.
I have the following build packages installed in my app:
Microsoft.Build
Microsoft.Build.Framework
Microsoft.Build.Tasks.Core
Microsoft.Build.Utilities.Core
The standard advice I've seen in forums for this error is to install Visual Studio on the build server, but I am doing this locally and I do have Visual Studio installed. I've also read that MSBuild 15 does not come with the WebApplication.targets file. There is also a toolsVersion parameter on the constructor for Microsoft.Build.Execution.BuildRequestData that I've tried setting manually to 14.0 but it still seems like my app is trying to use MSBuild 15. (I do have MSBuild 14 installed.)
Questions:
Can I make this build run in MSBuild 14 programmatically without updating any csproj files?
Where can I get WebApplication.targets for MSBuild 15?
Solution:
Thanks in large part to #Leo-MSFT I was able to get this working. Here's how:
Uninstalled the VS2017 ASP.NET and Web Application Development workload, then reinstalled with all of its optional components. This downloaded the missing .targets file.
In my builder application, added this property to my instance of BuildRequestData to make MSBuild look in the folders used by v15, rather than using the folders used by v14.
["MSBuildExtensionsPath32"] =
"C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild"
Can I make this build run in MSBuild 14 programmatically without updating any csproj files?
MSBuildExtensionsPath32 is set internally by MSBuild. If you do not want update you .csproj file, you can try to override the value in your project file:
<PropertyGroup>
<MSBuildExtensionsPath32>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild</MSBuildExtensionsPath32>
</PropertyGroup>
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" Condition="false" />
But I'm not sure if it will introduce other error(Not tested).
Where can I get WebApplication.targets for MSBuild 15?
The path of WebApplication.targets for MSBuild 15 is:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\VisualStudio\v15.0\WebApplications

Visual Studio 2013 Project Template Customization

I'd like to customize the UnitTest project template for Visual Studio 2013: We use Moq very often in UnitTest projects, hence I think it should be automatically referenced.
In C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\ProjectTemplates\CSharp\Test\1033\UnitTestProject, I edited UnitTestProject.csproj by adding a reference section and an ItemGroup:
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
...
<Reference Include="Moq, Version=4.2.1510.2205, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
<HintPath>..\packages\Moq.4.2.1510.2205\lib\net40\Moq.dll</HintPath>
<Private>True</Private>
</Reference>
Then I added the file packages.config to that folder, and edited UnitTestProject.vstemplate by adding
<ProjectItem ReplaceParameters="false" TargetFileName="packages.config">packages.config</ProjectItem>
to the Project section.
But when I create a new UnitTest project, I get the error message
The file packages.config could not be found within the project templates. Continuing to run, but the resulting project may not build properly.
After clicking OK, another error message follows:
Unable to copy the file 'packages.config' from the project template to the project. Cannot find file "(%TEMP%\some folder)\packages.config'.
How can that be solved?
Beyond changing the template in C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\ProjectTemplates, I had to replace it also in C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\ProjectTemplatesCache. Next, I had to look into %AppData%\C:\Users\bernhard.hiller\AppData\Roaming\Microsoft\VisualStudio\12.0\ProjectTemplatesCache and delete the zip-file for the template.
Now the packages.config file gets copied when I add a new Unit Test Project manually. But when using the "Unit Test Generator" (see https://visualstudiogallery.msdn.microsoft.com/45208924-e7b0-45df-8cff-165b505a38d7), this file is missing while all other changes to the project (post build actions, references, ...) are applied.

Calling VSDBCMD from inside a dbproj file

I have a standard sql server 2008 project which has been created using vs2010. I have been trying to modify the build process so that at the end a custom task should fire which would call VSDBCMD to generate a deploy script by comparing the output of the build (the dbschema file) against a static DBschema file. When I run this command from a VS2010 command prompt
vsdbcmd.exe /a:deploy /dd:- /dsp:sql /model:obj\Release\EnterpriseBuild.Services.Database.dbschema /targetmodelfile:VersionedSchemas\v1.0.dbschema /DeploymentScriptFile:NewDeploymentScript.sql /p:TargetDatabase="EnterpriseBuild.Database"
Everything works great and the newdeployment.sql file is generated. However when I modify my .dbproj file and include this as a AfterBuilds Target
<Target Name="AfterBuild">
<!--<Message Text="sample text" Importance="high"></Message>-->
<Exec IgnoreExitCode="false"
WorkingDirectory="C:\Program Files (x86)\Microsoft Visual Studio 10.0\VSTSDB\Deploy\"
Command="vsdbcmd.exe /a:deploy /dd:- /model:obj\Release\EnterpriseBuild.Services.Database.dbschema /targetmodelfile:VersionedSchemas\v1.0.dbschema /DeploymentScriptFile:NewDeploymentScript.sql /p:TargetDatabase="EnterpriseBuild.Database"" />
</Target>
the build fails with a
EnterpriseBuild.Services.Database.dbproj(211,5): error MSB3073: The command "vsdbcmd.exe /a:deploy /dd:- /model:obj\Release\EnterpriseBuild.Services.Database.dbschema /targetmodelfile:VersionedSchemas\v1.0.dbschema /DeploymentScriptFile:NewDeploymentScript.sql /p:TargetDatabase="EnterpriseBuild.Database"" exited with code 1.
message.
Can anyone suggest what I am doing wrong?
Visual Studio also exposes $(VSTSDBDirectory) - location of VSDBCMD
MSBuild task could look as follows:
<Exec Command=""$(VSTSDBDirectory)\Deploy\VSDBCMD" /a:Deploy /q+ /dd:+ /dsp:sql /manifest:"$(OutDir)Database.deploymanifest" /cs:"Integrated Security=SSPI;Persist Security Info=False;Data Source=(local)" /p:AlwaysCreateNewDatabase=true /p:CommentOutSetVarDeclarations=false /p:TargetDatabase="MyDatabase" /Script:"$(OutDir)MyDatabase.sql"" ContinueOnError="false" />
I managed to solve it. Basically doing this
<Target Name="AfterBuild">
<!--<Message Text="sample text" Importance="high"></Message>-->
<Exec IgnoreExitCode="false"
WorkingDirectory="C:\Program Files (x86)\Microsoft Visual Studio 10.0\VSTSDB\Deploy\"
Command="vsdbcmd.exe /a:deploy /dd:- /model:obj\Release\EnterpriseBuild.Services.Database.dbschema /targetmodelfile:VersionedSchemas\v1.0.dbschema /DeploymentScriptFile:NewDeploymentScript.sql /p:TargetDatabase="EnterpriseBuild.Database"" />
</Target>
rightly sets the working directory to C:\Program Files(x86)....where my VersionedSchemas\v1.0.dbschema etc. don't exist. The trick was to keep the working directory same as the ProjectDirectory and still call VSDBCMD. I managed this by doing
<Exec IgnoreExitCode="false" Command=""C:\Program Files (x86)\Microsoft Visual Studio 10.0\VSTSDB\Deploy\vsdbcmd" /a:deploy /dd:- /model:obj\Release\EnterpriseBuild.Database.dbschema /targetmodelfile:VersionedSchemas\v1.0.dbschema /DeploymentScriptFile:NewDeploymentScript.sql /p:TargetDatabase="EnterpriseBuild.Database"" />
The trick was to use & quot; around C:\Pro...

Resources