I want to do the following steps automatically:
Publish a web project from my solution.
Compile another project from my solution.
Put both projects in a folder together.
*Both projects need to have an auto-increment version control(Same version number for both).
Any ideas? using a post-after build batch files.
You can use msbuild for that.
you can find an example to publish with MSBuild here
Related
I have a CS project that depends on some archive files and I have created MSBuild targets to build them. I cannot, however, get MSBuild to build these targets if project's files are up to date.
I have tried referencing the archive targets in the following places:
The project's before and after build targets
The project's InitialTarget and DefaultTarget attributes
In a separate targets file, which I tried to add as a project reference to my project. I'm not sure I used the item correctly though.
When I build, Visual Studio tells me that my project is up to date and does nothing. How can I make it consider my other targets as dependencies?
It seems that you build the project in VS IDE. VS IDE has a up-to-date check, if the project's output files are up-to-date with respect to their corresponding input files, it won't start build process.
I cannot, however, get MSBuild to build these targets if project's
files are up to date.
Check this thread, if the input source files and output assemblies are corresponding up-to-date, VS won't really build and won't call your custom targets.
And according to your description, what you want is to run your target no matter if project file is up-to-date, I'm not sure what you mean make it consider my other targets as dependencies.What you really want is to run the custom targets anyway, if so, you can build the project by command-line or try rebuild instead of build button in VS. If I misunderstand anything, please feel free to let me know.
I have a project (.NET Core targeting .NET 4.6.1) that has lots of libraries in it. When I build the project from Visual Studio all assemblies are created correctly.
But when I delete the bin and obj folders and try to rebuild from PowerShell with dotnet publish, one of the libraries' assembly gets created badly; it's only half the file size and it doesn't work when I run the functionalities of that library.
The problem exist because I need to publish it through Team City so I can't do it from Visual Studio.
Anybody got any idea why it's behaving like this?
Is it possible to make Visual Studio to copy all dependencies of referenced projects into the output path?
Example
In the Solution, Project A (Library, .NET Standard) defines some functions and is dependent on Library L1 (via NuGet) and Library L2 (local .dll, referenced and copied to project)
Project B (Console Application) references Project A.
When building B, The output folder contains all direct dependencies of B and A.dll. L1 and L2 are not available in the output. Therefore, the program does not work correctly.
How can I force VS to copy also L1 and L2 to the output of B?
The only way I found so far is packing A as NuGet, but this seems to be unnecessary overhead and uncomfortable. I think I am just forgetting something everyone else seems to know...
Edit (clearifying Example)
My solutions consists of two projects.
Project MongoWrapper
.NET Standard 2.0 class Library
depends on NuGet MongoDB.Driver package
Actually uses this dependency (no zombie dependency)
Project ConsoleUser
.Net Framework 4.6.1 Console Application
References MongoWrapper project
Actually uses MongoWrapper
Observation
When debugging the ConsoleUser application, it compiles and starts. During runtime, when it calls a method in the MongoWrapper which uses the MongoDB.Driver, the application crashes, as the MongoDB.Driver dependency was not copied into the output folder of the ConsoleUser.
How to fix this?
The problem was introduced by the usage of .Net Standard library and a .Net Framework application.
TLDR
Open the .csproj file of the .Net Framework project with a text editor. Inside the first PropertyGroup add the line
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
Save the file, reopen Solution in Visual Studio and perform Clean & Build
Dependencies in different project file versions
.Net Framework projects use an old version of the .csproj project files. References/Dependencies are stored in the additional packages.configfile. By default, building a .Net Framework project makes the system to search for a packages.config file in the referenced projects. If no such file is found, the build task treats the referenced project as having no dependencies. Therefore, in the example, the MongoDB.Driver library is not added.
By adding the proposed line in the .csproj project file, the build task searches the project file of the referenced project for dependencies, where they are stored in .Net Standard project files.
.Net Core projects by default search for the newer project file structure.
The default behavior for new projects can be set in the Options -> NuGet -> General -> Package Management
Is it possible to make Visual Studio to copy all dependencies of referenced projects into the output path?
Yes.
This is what publishing the application does - it prepares the application for deployment. When you publish, it will include all of the dependencies that the application requires to run in the output.
Use the Publish tool to deploy to a local folder. The exact options available depend on your app type. In Solution Explorer, right-click your project and choose Publish, and then choose Folder. For more information, see Deploy to a local folder.
Tutorial: Publish your Hello World application with Visual Studio 2017
Also see: .NET Core application deployment.
I am trying to achieve setting up a vNext build definition on TFS 2015 (the project is actually a .NET 4.6.1 web project, but I want to use the new TFS build setup). I am struggling with finding documentation on only deploying a specific web project in my solution (2 web projects, 3 class libraries and subsequent tests).
In the XAML build approach, I would specify the .sln and the .csproj file relevant to the build in the Process > 2. Build > Projects input. The "Visual Studio Build" step does not allow for multiple project inputs in the same way, and this seems to be where I am getting stuck. If I only specify the .csproj, Nuget packages do not get restored and the build fails.
Is there any known documentation for deploying a C# web project (.csproj) ONLY via these vNext builds?
MSBuild arguments previously used in XAML Build:
/p:AllowUntrustedCertificate=True /p:AuthType=NTLM /p:Configuration=Development /p:DeployOnBuild=True /p:PublishProfile="DEV" /toolsversion:14.0 /p:VisualStudioVersion=14.0 /p:GenerateBuildInfoConfigFile=false
The solution I am searching for would accomplish the following:
Builds at the very least the Web.csproj with project dependencies
Restores Nuget packages
Transforms web configs
Deploys Web project to two separate servers (non-Azure!) via, ideally, web deploy
Thanks in advanced for any help. Hopefully this is possible!
Note: I am not on Azure and Azure is not an option. I know there are tons of documented use case scenarios for Azure users, which is great... but, yeah.
You can add a "NuGet Installer" task at the top of your build definition to restore the nuget packages for your solution and specify the .csproj in Visual Studio Build Step.
If you want to build the entire solution, you can add following arguments in "MSBuild Arguments":
/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactstagingdirectory)\\"
This will create the deploy packages for your projects separately in "$(build.artifactstagingdirectory)\" folder like following:
Then you can choose the package for the project you want to deploy. And with the deploy package, you can add two "Command Line" tasks in your build definition and call "Project.deploy.cmd" under "$(build.artifactstagingdirectory)\" folder to deploy the project to your servers. Reference about deploy from command: Executing the Command File. Web.config will be transformed by default if you have configured it correctly.
By the way, I recommend you to deploy your projects by using the release management system instead of deploying them in build.
I have used .Net Reactor to obfuscate code. Now how do I create create setup package for the obfuscated code. Or are there any other tool for creating setup package for obfuscated code.
Thanks in advance.
Not sure why this is a problem. Why don't you create the setup package before obfuscating the assemblies?
I had no problem with BitHelmet Obfuscator. My setup package just uses the obfuscated assemblies in BitHelmet's output folder, instead of project output.
Works fine.
Are you using the VS included setup project? For that, the obfuscator needs to support MSBuild based obfuscation, so that the obfuscation takes place as part of build process. This way, the obfuscated dlls are available for the setup project.
I found a way to do with Dotfuscator. Below are the steps.
You need to create Dotfuscator project first, i.e right click on solution->add project->select Dotfuscator as project type. To the project created right click on Input-> map to project output from your actual project. Build the Dotfuscator project. Next add the setup project. Point setup project output to that of Dotfuscator. And now build to create the setup. Now your code is obfuscated.
Now I am looking for a solution to work with .Net Reactor, obfuscation and add the output to setup package.
You can use the .NET Reactor VS Add-in in to automatically obfuscate the assemblies. This way your setup package will include the obfuscated files.
The solution is described here: Solution